HomeMethod

Knowledge

Web VitalsTechniquesSnippetsAnswersImpactsBottlenecks

Disable self-pingbacks

  • Performance

When you link to one of your own posts, WordPress sends a pingback request to itself. This creates a comment-like entry in the database and wastes an HTTP request hitting your own server. It’s entirely useless.

disable-self-pingbacks.php
<?php
/**
 * Disable Self-Pingbacks
 *
 * WordPress pings itself when you link to your own posts, creating
 * unnecessary pingback entries in the comments table and firing HTTP
 * requests to your own server. This is pure waste — disable it.
 *
 * Usage: Add to functions.php.
 *
 * @category performance
 * @language php

 *
 * @author Adame Dahmani https://adame.io
 * @support Support my family project: https://adame.io/fundraiser
 */
add_action( 'pre_ping', function ( &$links ) {
    $home = home_url();
    foreach ( $links as $i => $link ) {
        if ( strpos( $link, $home ) === 0 ) {
            unset( $links[ $i ] );
        }
    }
} );
Support our family now