How to Disable Self Pings in WordPress

Depending on your WordPress configuration, plugins, and so forth, your site may be suffering from “self-pings”. Self-pings are pingbacks from your own domain, which are not necessary and look kind of silly displayed alongside other, actual pingbacks. If your site is haunted by self-pings, here is a quick code snippet to stop them.

// 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');

You can add that snippet via quick custom plugin or via your theme’s functions.php file. How it working? Basically the trick is hooking into pre_ping, which passes the array of pingback URLs for us to manipulate. So inside the function we compare each URL in the array and unset (remove) any links (pingbacks) coming from our own domain.

See also  How to Navigation Links for Monthly Archives Wordpress

Leave a Reply

Your email address will not be published. Required fields are marked *