4 Methods to Disable DiggBar on Your Site
Posted by Mayur Somani in Programming Trix
Digg recently introduced DiggBar. DiggBar lets you Digg, find related content, read comments, and do many other cool things,
However, there are some serious concerns with this new toolbar. Techcrunch thinks that digg introduced this toolbar to keep all the traffic on their own site. There are also some SEO issues with it. So, I decided to block diggbar on my site until Digg clarifies these issues. Following are some of the methods which can be used to block, remove or disable diggbar from your site-
1. Since diggbar uses HTML frames to display your page, you can easily block it by using a good javascript framekiller code.
1 2 3 | <script type="text/javascript"> if (top !== self) top.location.replace(self.location.href); </script> |
The following code is much better as it displays a pop up message to the user about why she is being redirected,
1 2 3 4 5 6 | <script type="text/javascript"> if (top !== self) { alert('The URL '+self.location.href+' cannot be viewed inside a frame. You will be redirected.'); top.location.href = self.location.href; } </script> |
Both the above framekiller codes have one drawback. They’ll display the diggbar for an instant before it is killed. The following javascript code snippet from farukat.es directly kills the diggbar without showing anything to the visitor.
1 2 3 4 5 | <script type="text/javascript"> if (top !== self && document.referrer.match(/digg.com/w{1,8}/)) { top.location.replace(self.location.href); } </script> |
To disable diggbar, simply copy any of the above code just before </HEAD> tag in your site.
If you are using wordpress you can find </HEAD> tag in header.php file of your theme. Also check out the second method below for a plugin that does this automatically.
2. Use No-Frames wordpress plugin if you are a wordpress user.
3. Just copy paste the following php code snippet to block diggbar anywhere between <HEAD> and </HEAD> in your site.
1 2 3 4 5 6 7 | <?php if (preg_match('#http://digg.com/w{1,8}/*(?.*)?$#', $_SERVER['HTTP_REFERER']) ) { echo "<p>I kinda doesn't like diggbar, Sorry :)</p>"; exit; } ?> |
[via daringfireball]
4. Techzilo combined the php and javascript solutions,
1 2 3 4 5 6 7 8 9 | <?php if (preg_match('#http://digg.com/\w{1,8}/?$#', $_SERVER['HTTP_REFERER']) ) { ?> <script language="JavaScript" type="text/javascript"> if (top.location != self.location) top.location.replace(self.location); </script> <?php exit; } ?> |
This code simply checks if the visitor is viewing a DiggBar URL using a simple PHP regular expression, and if it is true, then the javascript code kills the frame.
Simply copy it anywhere between the HEAD tag to block DiggBar.




Interesting! I never thought they were actually blocking traffic to my site, since my site has never gone to DIgg’s front page. I will definitely consider adding this code to my site.
But I have one question, why not simply closing the digg bar as shown in the video? Won’t that work?
Musab, you need not worry about SEO issues now. Diggbar has been changed due to all this controversy, it will not be visible to users who are not logged into their Digg accounts. Also, all the Digg’s URLs will now do a 301 redirect to the original URL. So, Enjoy!
WoW! That’s great! Thanks for clarifying this issue Mayur…
I used it for my pics site,is it bad for google seo??
thanks a million~~
@sexy2funny
No, it isn’t.