JavaScript and PHP codes to remove DiggBar


Digg recently introduced DiggBar to mixed reactions. We also shared a Greasemonkey script to remove DiggBar, only to discover later that it can be turned off from Digg preferences. However, DiggBar is enabled by default, and most readers are unlikely to turn it off themselves. Here is a JavaScript code to remove DiggBar – bloggers and webmasters who find DiggBar damaging would probably find this useful.

Reasons to remove DiggBar

So, what is the damage? DiggBar does a 200 HTTP code (hence depriving sites of Google juice). If a hundred sites link to your blog using the Digg shortened URL, all that juice goes to Digg.

Can rel=”canonical” be used to suggest a canonical url on a completely different domain?

No. To migrate to a completely different domain, permanent (301) redirects are more appropriate. Google currently will take canonicalization suggestions into account across subdomains (or within a domain), but not across domains. So site owners can specify a canonical page on from a set of pages on or, but not on


About rel=canonical, Google Webmasters help

Canonical tag which would not work (because canonical tags work only within a domain, not cross-domain).

How to remove DiggBar (code)

Initially, this article contained only the JavaScript method, but upon further searching, I also found a PHP code. Both methods are shown here, and each is useful for different scenarios.

Javascript code

The JavaScript method redirects the user to the actual page. Enter this code block within head tags of your pages.

<script language="JavaScript" type="text/javascript">
if (top.location != self.location) top.location.replace(self.location);

The above code removes all frames, including the frames created by Google Image search. If you do not like image search visitors seeing the above code, use it always. If you wish to remove DiggBar only, use it only when your blog is Dugg/about to be dugg. That way, you can have the best of both worlds – image search visitors see the frame on top while DiggBar is removed during the influx of visitors (which is when your visitors will link to you and bookmark you.

PHP code

John Gruber posted a PHP snippet that detects DiggBar (from the URL) and shows them a greeting message.

This PHP snippet merely shows a message to the visitor and stops loading the page – without redirecting the user. You may want to show a hyperlink to the actual page.

<?php if (preg_match('#\w{1,8}/?$#',
echo "<p>Special message for Digg users here.</p>";

The above code checks whether the referral URL is followed by 1 to 8 characters – which is typical of the DiggBar. If yes, it shows a message to the visitors (written within quotes on line 2) and stops loading page.


Comments are closed.