Content & Posts PHP Beginner

Disable Self-Pings on Your Own Posts

Prevent WordPress from sending a pingback to itself when you link to your own content in a post, eliminating unnecessary internal self-pings that clutter your comments moderation queue.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 8 lines
add_action( 'pre_ping', function( &$links ) {
    $home = home_url();
    foreach ( $links as $key => $link ) {
        if ( strpos( $link, $home ) === 0 ) {
            unset( $links[ $key ] );
        }
    }
} );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

When you publish a post that contains a link to another post on your own site, WordPress’s pingback system fires and sends a pingback notification to that linked post. The linked post then receives a pingback comment in its moderation queue, a notification that your own site linked to itself. This is a pointless round-trip: you already know your own site linked to itself, and the pingback clutters your comment moderation with entries you’ll never approve or that get auto-approved as spam noise.

What the code does

It’s one of the most concise and effective debloat snippets available, a single function that filters out your own domain from the list of URLs to ping before pingbacks are sent.

How It Works

The pre_ping action fires with a reference to the array of links found in the post content that are candidates for pingback. The snippet loops through this array and removes any URL that starts with your site’s home URL. WordPress then processes the remaining links, external sites that legitimately should receive pingbacks, and skips your own domain entirely.

The & before $links in the function signature is important, it passes the array by reference, meaning modifications to $links inside the function affect the original array that WordPress will process. Without the reference, the changes would be discarded.

External Pingbacks Still Work

This snippet only removes self-referential pings. If you link to another site that supports pingbacks, that pingback still fires normally. The filter is surgical, it targets only URLs that begin with your own home URL and leaves all external links untouched.

If You’ve Disabled Pingbacks Globally

If you’ve already disabled pingbacks and trackbacks site-wide through Settings → Discussion → unchecking “Allow link notifications from other blogs”, this snippet is redundant, no pings are sent at all. This snippet is most useful on sites where you want to keep pingbacks enabled for external links (to notify other sites when you cite them) but eliminate the noise of self-pings specifically.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only