How To Disable Self Pingbacks in WordPress Without a Plugin

By default, WordPress blog automatically send a pingback to itself any time you link to one of your own internal old post. It would be nice if this self-pingback feature can be turned off in the dashboard.

Self-pings, or pings within your own blog, are found useful by some, annoying by others. Those who find them useful feel that self-pingbacks is a good approach to increase inter-linking between posts.

You can stop self-pings if you wish. You can simply manually delete them once you get them in the WordPress dashboard, or you can use one of the 2 methods below to automatically disable self-pings to your own blog.

What are Pingbacks?

Pingbacks are automated cross referencing system between blogs. Pingbacks are designed that you receive a notification when another blog links to one of your posts. For more details, read my previous tutorial: Trackbacks and Pingbacks in WordPress.

What About a Plugin?

There are plugins that disable self pingbacks but you really don´t need a plugin for such a simple task. Also I encourage you to read my previous post about unnecessarily adding plugins to your theme. Personally, I am not a fan of plugins, I prefer to use a snippet of code instead.

How Self Pingbacks are Created

The best way to learn about self pingbacks is to create an internal link from one post to another on your blog. You will then find a pingback in your comment section.

Below is a screenshot showing 2 pingbacks after I inserted two internal links in a new post of mine to two other older posts on this blog.

Boutros AbiChedid Blog. I linked to 2 older posts from a new post. Thus WordPress automatically created 2 self-pingbacks that appeared on the dashboard as comments.

If the 2 pingbacks above are approved, they will show up as comments in the 2 older posts respectively. For this time, I approved them both and you can check them out at old post1 comment and old post2 comment.

If Comments are closed for an older post, and you linked to it from a newer post on the same blog, then self-pingbacks will not be sent by WordPress. This is the only case, that WordPress will not send self-pingbacks if you decide not to take action by choosing either of the methods below.

2 Methods to Disable Self Pingbacks

If you don´t want to get self-pingbacks on your blog, you have 2 choices to stop self pingbacks from showing up as comments on your posts. Either method is just fine.

METHOD1 | No Self-Pingbacks | functions.php

One way to disable self-pings is to add CODE-1 to your theme´s functions.php file. Open the functions.php file located in your theme´s folder, and add (copy and paste) the following CODE-1. Save the file and upload it to the server.

CODE-1 :: Method1 to disable Self Pingbacks

Note: To scroll within the code: You can also click on the code window and use your keyboard´s arrow keys.

<?php
/* No Self Pings */
//Pass the variable by reference to the function, so the function can modify the variable.
function no_self_ping (&$links) {
$home = get_option( 'home' );
foreach ( $links as $l => $link )
    //Find the position of the first occurrence of a substring in a string.
    //($a === $b) Identical operator. TRUE if $a is equal to $b, and they are of the same type.
    if ( 0 === strpos( $link, $home ) )
        //Unset the variable
        unset($links[$l]);
}
//Hooks the function to the specific action (pre_ping)
add_action( 'pre_ping', 'no_self_ping' );
?>

CODE-1 Notes:

Self pingbacks are now disabled. Source WordPress forum.

Some themes, or theme frameworks, have more variations of the functions.php file, so look at their documentation and see where best to add the code.

CODE-1 is tested to work on WordPress version 3.3.1

CODE-1 References:

METHOD2 | No Self-Pingbacks | Use Relative Path for Links

Another option to avoid self pinging, is to use relative path for the links in your post instead of absolute path. In other words, Replace the absolute links of your internal posts with relative links.

//Replace the Absolute link of the internal post
<a href="http://bacsoftwareconsulting.com/blog/index.php/wordpress-cat/tips-for-maximum-wordpress-performance-and-speed/">Absolute path</a> 
//With the following Relative link:
<a href="/index.php/wordpress-cat/tips-for-maximum-wordpress-performance-and-speed/" title="14 Tips ...">Relative Path</a> 

Of course, relative Links in your case are most likely different than in my case. It all depends on the structure of your blog's directory.

For more information on Absolute versus Relative Paths see tutorial1 and tutorial2.

General Warning

When you add several PHP code blocks in your theme´s funtions.php file, make sure that you do NOT leave any white space (spaces, newline) before the opening PHP tag (<?php) or after the closing PHP tag (?>). The correct way is as follows:

<?php 
//Some Code here beetween the opening PHP tag (above) 
//and the closing PHP tag (below)...
?>
<?php 
//Some other Code here ...
?>

In the above code, if you leave any white space or a newline between lines 4 and 5, you will get the following error: “Warning: Cannot modify header information - headers already sent by…

Your Turn to Talk

You now have the choice to disable self-pingabcks, without a plugin, and keep WordPress blog from pinging itself.

Some bloggers like to use the self-pinging feature as they find it beneficial for better inter-linking between posts, which I understand their point. The majority of the time I tend to delete self-pingbacks.

How easy did you find this tutorial to implement? I am interested to know your thoughts on the self-pingback feature. Do you have something to add? If so, please share your opinion in the comments section. Your opinion matters, unless it is a Spam.

If you found this post useful, please consider: linking back to it, subscribing by email to future posts, or subscribing to the RSS feed to have new articles delivered to your feed reader, or feel free to donate. Thanks!

About the Author |
Boutros is a professional Drupal & WordPress developer, Web developer, Web designer, Software Engineer and Blogger. He strives for pixel perfect design, clean robust code, and user-friendly interface. If you have a project in mind and like his work, feel free to contact him. Connect with Boutros on Twitter, and LinkedIn.
Visit Boutros AbiChedid Website.

9 Responses to “How To Disable Self Pingbacks in WordPress Without a Plugin”

  1. andrei says:

    Thank you for post. I resolved my problem

  2. Hi Boutros, thanks for nice article and snippet. Pingbacks on my site maybe not really useful to my reader so i’ll try.

  3. David says:

    Thanks for the snippet!
    I really like the design of your site! I thought there was one thing you might want to consider. When the page was loading, the background image for the content took a while to come in (I was at a coffee shop). As a result, I had brownish text on a brown background, and I almost left due to the difficulty in reading. Then the background came in, and I read the rest of the article.

    A simple way to remedy it would be to add a white colored background that loads instantly in the mean time, while the image loads.
    Given the way the formatting is setup, it would take a little bit more than a quick snippet I could post here, but it wouldn’t be hard.

    Just hate for you to lose visitors that are loading the site over a slow connection.

    Cheers!

    PS – Thank you for adding the subscribe to comments option!

    • Thanks for the feedback/tip David.
      You are right, after checking the CSS file for this theme, I did not have a fallback ‘straight-color’ background in case the images are slow to load.
      I also have 3 other themes that you can choose from (on the right sidebar) that should load faster.
      Thanks.
      Boutros.

  4. Paul says:

    I think this functionality belongs in a plugin. Any functionality that isn’t theme specific should be put in a plugin not a theme (functions.php). This is because if you ever change the theme you will suddenly start getting self pingbacks.

  5. Thomkins Rosewell says:

    You get notified when another blog links to one of your posts. This kind of tool is useful though especially if you want to stay in the trend. Thanks for this.

  6. Rahul says:

    Let me try …. is there any option in wordpress to remove ping back

  7. chuck scott says:

    Hey Boutros AbiChedid – kudos to informative post … have not tried your code suggestions referenced in said post but wanted to literally “ping back” to you on extra spaces in code … this is one of those areas, space breaks or necessity of lack there-in (space breaks that is), is terrain that is seemingly simple to grasp, easily overlooked, and later found to be root source for painful errors but i digress … cheers from connecticut … cordially, chuck scott