If you’ve ever linked to another post on your WordPress website, you’ve likely seen trackbacks or “self-pings” appear in the comments section.
While trackbacks can be helpful for linking between different sites, self-pings within your own site can clutter your comments section unnecessarily.
Thankfully, WordPress offers a simple way to prevent these internal pings.
Adding a small snippet can effectively stop self-pings. Here’s the code:
// prevent self-pings
function shapeSpace_prevent_self_pings(&$links) {
$home = get_option('home');
foreach ($links as $l => $link) {
if (0 === strpos($link, $home)) unset($links[$l]);
}
}
add_action('pre_ping', 'shapeSpace_prevent_self_pings');