Disable Self-Pingbacks

Disable self-pingbacks in WordPress, which are notifications sent to yourself when you link to your own posts.

<?php
/**
 * Disable self-pingbacks.
 *
 * @param  array $links An array of links to ping.
 * @return array The filtered array of links.
 */
function disable_self_pingbacks( $links ) {
    // Get the URL of the current site
    $home = home_url();

    // Loop through the array of links
    foreach ( $links as $key => $link ) {
        // Check if the link contains the current site's URL
        if ( strpos( $link, $home ) === 0 ) {
            // Remove the link if it's a self-pingback
            unset( $links[ $key ] );
        }
    }

    return $links;
}

// Apply the function to the 'pre_ping' filter
add_filter( 'pre_ping', 'disable_self_pingbacks' );

Post Comment