WP-Mix

A fresh mix of code snippets and tutorials

WordPress Disable Self Pings

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.

Learn more

Digging Into WordPressWordPress Themes In DepthWizard’s SQL Recipes for WordPress