X

Disable Self Pings with pre_ping Hook

Snippets by IsItWP

Do you want to disable self pings to your WordPress blog? While there’s probably a plugin for this, we have created a quick code snippet that you can use to disable self pings with pre_ping hook in WordPress.

Instructions:

All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:

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

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 15 best content marketing tools and plugins and how to set up download tracking in WordPress with Google Analytics.

Comments   Leave a Reply

  1. this doesn’t work, error:
    Fatal error: Cannot redeclare no_self_ping()

    1. Hi That error means you have the function no_self_ping in your functions.php already.

Add a Comment Cancel reply

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!