Skip to content

Instantly share code, notes, and snippets.

@shirokoweb
Last active January 29, 2018 10:51
Show Gist options
  • Save shirokoweb/217e5617c2589e1b710a54c6dc18a86b to your computer and use it in GitHub Desktop.
Save shirokoweb/217e5617c2589e1b710a54c6dc18a86b to your computer and use it in GitHub Desktop.
starter setup for divi child theme
<?php
// Disable pingback.ping xmlrpc method to prevent Wordpress from participating in DDoS attacks
// remove x-pingback HTTP header
add_filter('wp_headers', function($headers) {
unset($headers['X-Pingback']);
return $headers;
});
// disable pingbacks
add_filter( 'xmlrpc_methods', function( $methods ) {
unset( $methods['pingback.ping'] );
return $methods;
});
add_filter( 'auto_update_translation', '__return_false' );
// Remove Divi calls to Google fonts API
function remove_google_fonts() {
wp_dequeue_style( 'divi-fonts' );
wp_dequeue_style( 'et-gf-open-sans' );
} add_action( 'wp_enqueue_scripts', 'remove_google_fonts', 20 );
// Enqueue styles
function theme_enqueue_styles() {
wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css');
} add_action('wp_enqueue_scripts', 'theme_enqueue_styles');
// Async scripts
function xxx_async_scripts( $tag, $handle, $src ) {
$async_scripts = array( 'webkit');
if ( in_array( $handle, $async_scripts ) ) {
return '<script type="text/javascript" src="' . $src . '" defer="defer"></script>' . "\n";
} return $tag;
} add_filter( 'script_loader_tag', 'xxx_async_scripts', 10, 3 );
function xxx_init() {
wp_enqueue_script('webkit', 'https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js', null, null, true );
wp_enqueue_script( 'fonts', get_stylesheet_directory_uri() . '/fonts.js', null, null, true );
} add_action('wp_enqueue_scripts', 'xxx_init');
// Remove the ver query argument from the source path
function tm_remove_query_string_version( $src ){
return remove_query_arg( 'ver', $src );
} add_filter( 'script_loader_src', 'tm_remove_query_string_version' );
// Unset WordPress jQuery Migrate.
add_filter( 'wp_default_scripts', $af = static function( &$scripts) {
if(!is_admin()) {
$scripts->remove( 'jquery');
$scripts->add( 'jquery', false, array( 'jquery-core' ), '1.12.4' );
}
}, PHP_INT_MAX );
unset( $af );
function disable_emojis() {
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
add_filter( 'tiny_mce_plugins', 'disable_emojis_tinymce' );
add_filter( 'wp_resource_hints', 'disable_emojis_remove_dns_prefetch', 10, 2 );
} add_action( 'init', 'disable_emojis' );
function disable_emojis_tinymce( $plugins ) {
if ( is_array( $plugins ) ) {
return array_diff( $plugins, array( 'wpemoji' ) );
} else {
return array();
}
}
function disable_emojis_remove_dns_prefetch( $urls, $relation_type ) {
if ( 'dns-prefetch' == $relation_type ) {
$emoji_svg_url_bit = 'https://s.w.org/images/core/emoji/';
foreach ( $urls as $key => $url ) {
if ( strpos( $url, $emoji_svg_url_bit ) !== false ) {
unset( $urls[$key] );
}
}
} return $urls;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment