Disabling pingback and trackback notifications

To disable pingback and trackbacks, add this code to your functions.php file in your child theme:

add_action( 'pre_ping', 'wpse_190346_internal_pingbacks' );
add_filter( 'wp_headers', 'wpse_190346_x_pingback');
add_filter( 'bloginfo_url', 'wpse_190346_pingback_url') ;
add_filter( 'bloginfo', 'wpse_190346_pingback_url') ;
add_filter( 'xmlrpc_enabled', '__return_false' );
add_filter( 'xmlrpc_methods', 'wpse_190346_xmlrpc_methods' );

function wpse_190346_internal_pingbacks( &$links ) { // Disable internal pingbacks
    foreach ( $links as $l => $link ) {
        if ( 0 === strpos( $link, get_option( 'home' ) ) ) {
            unset( $links[$l] );
        }
    }
}
function wpse_190346_x_pingback( $headers ) { // Disable x-pingback
    unset( $headers['X-Pingback'] );
    return $headers;
}
function wpse_190346_pingback_url( $output, $show='') { // Remove pingback URLs
    if ( $show == 'pingback_url' ) $output="";
    return $output;
}
function wpse_190346_xmlrpc_methods( $methods ) { // Disable XML-RPC methods
    unset( $methods['pingback.ping'] );
    return $methods;
}

Alternatively, you can use the Disable Blogging plugin which takes care of disabling the pingback/trackbacks for you.

Leave a Comment