How to use hotlinkers and Google Images to build natural links to your site

  • 0
  • June 7, 2007

Are you tired of people using images from your website without linking back to you? This simple script has the answer.

View the demo here (right click on the image). Note that I prefer to only run this script for users who arrive from an image search engine rather than for everybody.

Most website owners hate hotlinkers and blame them for stealing valuable bandwidth and costing the website owner money without giving anything in return. In fact, images can be a very valuable way to build links to your site.

First of all, a few points to note. If you want to stop people hotlinking your images this script isn’t for you, turning off hotlinking is an easy option in cPanel and fairly straightforward in htaccess as well. Also this strategy isn’t really recommended unless you have unlimited bandwidth hosting. Some sites using this script use over 100GB a week just from hotlinked images.

The good stuff

Remember that the majority of internet users who are looking for images to use on an eBay auction, blog post, myspace profile etc aren’t aware of the implications hotlinking can have and are even less aware of the benefits that the backlink will provide to your website.

Most of you are probably thinking that your regular users will be upset if they can’t use the right click function and you are quite correct.
The best way to make use of the script is to only show it to visitors who arrive from Google Images, Yahoo Images or MSN Live Search Images. Most of these visitors are likely to be after your images rather potential new customers so its safe to use this script. The key is to set a cookie when they arrive that expires after an hour, if the visitor likes your site and stays around you don’t want to upset them.

Of course if your site doesn’t have any regular users but enjoys traffic from Google Images then it might be acceptable to use this script all the time, in that case simply remove the cookie dependence.

What if I have thousands of pages?

This script works perfectly on database driven sites with lots of pages as long as your images are referenced in the database somehow. For example a product site will have an image of a product on each page and you will be able to use the image location to populate the textbox that hotlinkers will see.

If you are running a blog with lots of images embedded in the posts the script is a little harder to install. My favourite method is to parse the entire post and use a preg_match to find and output the images.


$match = Array();

if (preg_match(“/]*>/”, $blogpost, $match) !== FALSE) {

// Make sure it truely was a match

if ((count($match) != 0) && ($match[0] != “”)) {

// Save the image

$theImage = $match[0]; //image now saved as $theImage




Note: make sure you add a safeguard to handle posts with no images.

The script

Click here for the code

Patrick Altoft

About Patrick Altoft

Patrick is the Director of Strategy at Branded3 and has spent the last 11 years working on the SEO strategies of some of the UK's largest brands. Patrick’s SEO knowledge and experience is highly regarded by many, and he’s regularly invited to speak at the world’s biggest search conferences and events.

  • James Smith

    Wow. Neat idea. Thanks.

  • CMS

    Great tips :)

  • Brandon

    The script doesn’t work in your example… you can simply right click on the image and save it. Tested in Firefox 2.0

  • Patrick Altoft

    Hi Brandon.

    The script should work on most browsers, including Firefox, unless you have Javascript support turned off.

    It’s not really intended to stop people taking your images, the intention is to try and get a few links from the people who do.

    Even if it only works for 50% of the users it gets you 50% more links than without using it.:)

  • Gerald

    ok there are 3 parts to add this to my blogger?
    (just one page?)

    #1) Where do I add the “preg_match”

    #2) add a safeguard to handle posts with no images.( where do I get this safe guard?)

    #3) the script goes in the body?


  • Patrick Altoft

    Gerald I don’t think you will be able to run the php parts of this script using Blogger.

    However I will produce and test a version that is compatible with Blogger and other sites that can’t use php and post it to the blog later today. Smile

  • Gerald

    Thanks so much.


  • Gene

    Sound like a great idea, Thanks

  • Ingo Vogelmann

    Waiting for the WP Plug! ;o)

  • Junkie

    Trying to add it to the footer of and get the following errors –

    The following error occurred when attempting to evaluate this template:

    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/forumjun/public_html/includes/adminfunctions_template.php(3596) : eval()’d code on line 44

    This is likely caused by a malformed conditional statement. It is highly recommended that you fix this error before continuing, but you may continue as-is if you wish.

  • KP

    Interesting and great idea… I will try it.

  • dao

    great plugin , 10x

  • syahid ali

    neat idea. thumbs up.

  • Martin Larsen

    I am not quite sure I understand how to use the script. Does just including it one each page make it work? By looking at the code, it looks to me as if you need a little more code to wrap each image on the page into the imagelayer stuff. Like a regex to grab all the images, and then embed them in the layers in a foreach.

    Is that correct?

    Another question. How is this script licensed? May I make a plugin for a CMS using it?

  • Patrick Altoft

    You would need to use a regex to grab the images and put them in the code. I have released a WordPress plugin and there is another developer working on a Joomla plugin.
    We are happy for you to create a plugin as long as you tell people where you got the idea and link back to this site.

  • Martin Larsen

    I was actually thinking about Joomla. How far is he?

  • azzam

    martin, i was planning on the Joomla version however have not yet got round to it to be honest got a bit tied down with other work and the issue with Joomla GPL licensing that has got us developers in a stir.
    If you are willing to do it then by all means go ahead. If not I will try to make some time for it.

  • TRex2003

    This does not work in Opera (I didnt expect it to work, Opera blocks all the right-click Scripts). If it really doesnt work in FF, then there is almost no sense in using it at all. I would use a layer above the image (the blank-trick).

  • Patrick Altoft

    It works in FF and IE 90% of the time.

  • RegisterCompass

    Thanks for information … does anyone has an example url to check the backlinks given from this script?

  • Martin Larsen

    I am a commercial Joomla developer myself, and the licensing issue is truly annoying!

    I need it for a private site so the licence issue does not matter here, though.

  • wandira

    Are there any way for this to work on Blogger account ?

  • Comrade Smack

    This doesn’t really work. Repressing the ability to right click doesn’t really stop anyone. You can still get to the images by File > Save as..-ing.

    The only real way to stop people from hotlinking is rather supressing it entirely or exchange it with a replaced image.

  • Denis

    Hello Patrick,
    Thank you for the idea. I’ve just implemented your script on our website, but it works not exatly the way it is supposed to work.

    When I right-click somewhere on the page (for example, I want to copy some text) the box with the code appears, but user expects to see context-menu and click “Copy”.

    Could you please tell if it is possible to make the code appear only when user right-clicks on the image, but not anywhere on the page?

  • HDR

    My Joomla website is very image heavy, I would kill for a Joomla mambot that would automate this script. Can you add me to some type of mailing list in case you ever release a Joomla version please?

  • HDR

    Hmm I can’t get this working. Do I add the php to my main template then the script to a content item?

  • CNC support

    I’m testing the script, however getting an error: Parse error: parse error, unexpected ‘{‘ in …
    line is
    if (isset($_COOKIE[“imagesearcher”]) {

    Not sure what the error is, { it is opening, but do not know where it close ??? Any idea

  • klaus

    A great idea, but I should prefer to wait for the WordPress Plugin.

    greatings from germany

  • jimmy

    It would be good if you could make it so that the code box is displayed without having to right click. So it is permanently there. Is there a way to do that?

    As right clicking on any where on the page will bring up the code box.

  • comments for myspace

    Do you have a page/forum/area with a more detailed description on how to install/add this for noobs? I really like the idea and it looks like it works awesome here in the sample but I am completely lost on how to add it to a non blog site. I would like to add it to a site like this myspace comment site but the code given above as the script confuses me a bit (total noob unfortunately lol). It looks like the code includes the code for the dog image above so does that mean we have to add this code to every page that has images and change the bottom part where the dog code is for each and every image? Are there other steps than just adding the code to the page? Maybe a step-by-step for a total dumbass noob somewhere lol?

    Regardless, it’s an awesome script and I hope I can figure out how to use it. Thanks for providing it!

  • colum kelly

    You do realise that anyone who knows html will be able to just delete the link to your site. Good idea though.

  • Bozdemir

    Again this may not work for some users, they may just copy the image source “”
    not the whole code Smile

  • weakish

    In iceweasel, this script works without disabling right click. I think this is the best result for both site owner and visitors.

  • – r y u –

    wow… this is a great idea =)

  • Ecommerce Solutions

    Nice idea, if they hotlink (and use your bandwith), you obtain an IBL in return. Seem fair.

  • Kitsap County Real Estate

    I’ve been chuckling for the last 5 minutes. What a great way to turn an irritation into a bonus! Talk about out-of-the-box thinking. Last month we had 3791 inbound links from Google Images, this month (on the 3rd) we’ve already had 652. This was beginning to become a problem. I’ve been manually re-branding my images with an ugly warning whenever I found someone hotlinking. I like this idea much better.
    PS- You can thank Text Link Ads for sending me to this article.

  • JFU

    I can see a benefit from tying to gain backlinks.

    But if someone is capable of creating an image on their site hotlinked to yours, then they should be able to view the page source and find the image src for ‘firefox-puppy.jpg’.

    On top of which, the print screen button works wonders for capturing stubbon images from web pages.

  • Chris

    What a cunning way to link build!

  • seo bristol

    Having just said how much I like this solution on SEJ I thought it only polite to thank you in person!
    Thank you for a great – out of the box – method of gaining links.

  • faithxp

    IS it applicable now to a blog site., I have a blog and I want to put that script on it., Is it possible.,?

  • Edie

    Hello, how is it looking with wordpress plugin? Thank you for reply.

  • Oleg

    Patric, is script supposed to prevent me from copying the above image from this post? If so it does not do it for me. I have tried from both IE and Firefox and was able to get the image in both. Am I missing anything?

    • Patrick Altoft

      The script was disabled when I moved to WordPress yesterday, sorry. The plugin still works though if you install it on your blog.

  • CashJuke

    That’s seriously neat.
    You got yourself a new reader 😀

  • Alan

    Great Idea.

    I have another take on the hotlinking issue – the harder you make it for people to ‘steal’ your bandwidth the less chance you have of someone returning to your site. It is almost as if you are saying to your visitor; “We don’t trust you, now go away!”

    We employ two different methods of encouraging people to link back when ‘borrowing’ images:

    1. In our images gallery our No Right click javascript has a simple message that says: “If ‘BORROWING’ images please credit: – Port Elizabeth Community Web Site” – slightly humorous and one more way to get our name and URL in front of our visitors.
    2. The images that are hotlinked eventually show up in our stats program as popular and then we go back to the image and add our URL – at least this way we get some advertising every time the image is shown.

  • Pingback: Image Hotlinking and SEO : Are There Any Benefits?()

  • johnl

    I have thousands of wallpapers on my site so it would be fantastic if this works

    I notice that a lot of people are having trouble with it though so can someone pos tif and when it works

    Also what is “I would use a layer above the image (the blank-trick).” mentioned in a comment above?

  • Masalaboard

    You do realise that anyone who knows html will be able to just delete the link to your site. Good idea though.

  • Dennison Uy

    I will definitely give this a shot. It would have been nice though if the JavaScript only prevented right-clicks on the image itself. Disabling right-clicks on the entire page may annoy users who try to copy text.

  • David Bradley

    I see what happens when I right-click the image in the demo page, is that what would be displayed if someone were to hotlink your image? I did an images search for blogstorm, clicked a graphic, that opened a post as normal.

    I have a script running that is presumably similar that shows the image along with a notice about hotlinking when someone clicks through from an image search.


  • EFlight

    A brillant and original idea… !!

  • Nebraska football

    Is there a way to use this for images on Ning social networks? I will gladly link to this site and do whatever – it would just be awesome if I can get this to work for a branded social network I’ve created!!

    Any help is appreciated!

  • Amir Mullick

    I have the sites below:

    They are proxies with the logo that is a unique image, and people are always using it for something, which is so awkward…thanks for this, I will tell my friends about it too, and it should help, so i will buy it soon too.

  • Fan of the Band

    Where is the script? I get a 404 page :(
    Please fix it.
    Thanks !

  • mascali

    Can you fix download link please?

  • liveimagephotodotcom

    is there anyway you can update your wordpress plugin, the box pops up if you right-click anywhere (link or image) on a page. Can you make exceptions to work on .jpg .gif .png only? thanks and great plugin.

  • Fan Of Smartphone

    Patrick, please fix the download link. When I try to download the script I got error 404 page.

  • Lassar

    I have been doing some reading on image search engines. According to what I have read that the thing to do is to stop frames.

    This is the javascript from Don’t Lose Your Google Image Search Traffic

    if (top.location != self.location) top.location.replace(self.location);

    More scripts to bust frames.  

  • John

    Very cool idea. The link to the script is broken though, can you fix that? I’d like to try and implement this.

  • Martin

    I think it is just too easy to copy the image like that, I can actually use Snagit to copy the image. I think it is good just to place the watermark on the image.

  • Laman Web

    Actually there is a simple way to overcome this? Just highlight the image and press Ctrl + C. Am I right?

  • pravalika

    how to improve

  • Pingback: How to Optimize Images in Joomla - JoomlaK()

  • Sujit

    Wonderful tips, thank you!!!

  • Berita Harian

    Nice idea, great tips..Thanks for sharing! :)

  • suzy

    vety great idea, it is wonderful!

  • stuartpturner

    Bit of a late question but – are there any conflicts running this script and using a digital watermark as well?

  • Rednael

    I used this technique on!
    Great tips!

  • james

    I wana do the same thing but by htaccess file. Do you have an idea how can it possible.

  • jakki

    Seems like a great idea.
    going to try it soon.
    Thanks for this useful option. :)

  • jamie m

    Wow this is actually useful, thanks for this, will it work if i add tracking code onto the links? I would like to see just out of interest the stats n clicking etc.

  • Steve

    Gee, I wondered why my "Save Image As" function wasn't working, the last time I tried to appropriate a few measly images that probably never would have been seen on my miserable excuse for a web site.

    Thanks for the post and the recent update. Does the plug slow load time?

    Steve Benedict

  • Pingback: 10 Powerful Tips to Leverage Content Theft | SEO Himanshu()

  • Otto Heaps

    Usefull post do you mind if i translate into Spanish for my blogs viewers? Thanks

  • Michael SEO Haley

    I have been in the SEO business for years and rarely pick up new tricks… but this is one of those magical moments. Thanks, you guys are cutting edge!

  • James Whitrow

    Thanks very much for this! Not sure how I didn’t come across this before, will be very useful for many of my clients. Keep up the awesome work!

  • Preston Dental

    Great tips, dead easy but extremely useful, Genius !!! thanks

  • Berita Terkini

    Does just including it one each page make it work? By looking at the code, it looks to me as if you need a little more code to wrap each image on the page into the imagelayer stuff. Like a regex to grab all the images, and then embed them in the layers in a foreach.

  • Steve Rick

    I was just looking for something like this.

  • edybala

    Really like your section at the footer of your posts. I am new to coding. Do you have a post on how to create that? Thanks!

Like what you see? Talk to an Expert