Skip to main content
Login Join
Snippet · PHP

Disable Self Pingbacks in WordPress

Shared by Amit Dholiya · May 28, 2026

11 views
Back to Snippets

WordPress can create unnecessary self-pingbacks when you link to your own posts internally. Disabling them helps keep comments cleaner and reduces extra requests.

Steps

  1. Open your WordPress theme functions.php file.
  2. Add the code below at the end of the file.
  3. Save the file.
  4. Publish or update a post to test it.

Done — WordPress will stop sending pingbacks to your own website.

function disable_self_pingbacks(&$links) {
    foreach ($links as $l => $link) {
        if (0 === strpos($link, home_url())) {
            unset($links[$l]);
        }
    }
}
add_action('pre_ping', 'disable_self_pingbacks');
Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments