WPSurfer.com

How to Disable Self Pingbacks in WordPress

Published on September 24, 2022 | Updated on September 24, 2022

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');
Manuel Campos

Manuel Campos

I am José Manuel. I am writing about things I know and things that I am learning about WordPress. I hope you find the content of this blog useful.