Preventing Self Pings

If you have pingbacks switched on for your WordPress site (Settings -> Discussion and then tick ‘Allow link notifications from other blogs (pingbacks and trackbacks) on new articles’) then one annoyance is ‘self pings’ when you link to one of your posts from another.

Well, self pings can be prevented with a simple script, added to your functions.php file.

<?php
function no_self_pings( $links ) {
foreach ( $links as $loop => $link ) {
if ( 0 === strpos( $link, get_option( 'home' ) ) ) { unset( $links[ $loop ] ); }
}
}
add_action( 'pre_ping', 'no_self_pings' );
?>
view raw functions.php hosted with ❤ by GitHub

And that’s it. There are no settings – just peace in your inbox.

Talk to me!

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from David Artiss

Subscribe now to keep reading and get access to the full archive.

Continue reading