Disable Self Pingbacks

add_action( ‘pre_ping’, function( &$links ) { $home = get_option( ‘home’ ); foreach ( $links as $l => $link ) { if ( 0 === strpos( $link, $home ) ) { unset( $links[ $l ] ); } } } );Continue reading

Remove Query Strings From Static Files

function wpcode_snippet_remove_query_strings_split( $src ) { $output = preg_split( “/(&ver|\?ver)/”, $src ); return $output ? $output[0] : ”; } add_action( ‘init’, function () { if ( ! is_admin() ) { add_filter( ‘script_loader_src’, ‘wpcode_snippet_remove_query_strings_split’, 15 ); add_filter( ‘style_loader_src’, ‘wpcode_snippet_remove_query_strings_split’, 15 ); }…Continue reading

Add default ALT to avatar/Gravatar Images

add_filter( ‘pre_get_avatar_data’, function ( $atts ) { if ( empty( $atts[‘alt’] ) ) { if ( have_comments() ) { $author = get_comment_author(); } else { $author = get_the_author_meta( ‘display_name’ ); } $alt = sprintf( ‘Avatar for %s’, $author ); $atts[‘alt’]…Continue reading

Disable Embeds

/** * Disable all embeds in WordPress. */ add_action( ‘init’, function () { // Remove the REST API endpoint. remove_action( ‘rest_api_init’, ‘wp_oembed_register_route’ ); // Turn off oEmbed auto discovery. add_filter( ’embed_oembed_discover’, ‘__return_false’ ); // Don’t filter oEmbed results. remove_filter( ‘oembed_dataparse’,…Continue reading

Disable Emojis

/** * Disable the emojis in WordPress. */ add_action( ‘init’, function () { 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’,…Continue reading

Completely Disable Comments

add_action(‘admin_init’, function () { // Redirect any user trying to access comments page global $pagenow; if ($pagenow === ‘edit-comments.php’) { wp_safe_redirect(admin_url()); exit; } // Remove comments metabox from dashboard remove_meta_box(‘dashboard_recent_comments’, ‘dashboard’, ‘normal’); // Disable support for comments and trackbacks in…Continue reading