最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

functions - Disabling pingback and trackback notifications

programmeradmin1浏览0评论

I'm trying to disable pingback / trackback email notifications and was wondering if there's a PHP file I can edit to prevent them?

I've disabled them in the main WordPress settings (which I think just changes the default on new posts?) but still getting notifications of trackbacks on a post that's actually not a real post but a portfolio item in a portfolio plugin (with no option of disabling them on a per-post basis).

I'm trying to disable pingback / trackback email notifications and was wondering if there's a PHP file I can edit to prevent them?

I've disabled them in the main WordPress settings (which I think just changes the default on new posts?) but still getting notifications of trackbacks on a post that's actually not a real post but a portfolio item in a portfolio plugin (with no option of disabling them on a per-post basis).

Share Improve this question edited Aug 20, 2016 at 19:52 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Jun 3, 2015 at 13:25 SamSam 413 bronze badges 1
  • has this question bee resolved? Did my answer help? – Ethan Rævan Commented Aug 23, 2016 at 12:43
Add a comment  | 

1 Answer 1

Reset to default 1

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.

发布评论

评论列表(0)

  1. 暂无评论