Home Plugins Linked Image

Linked Image


If, like me, you have blogs where you use to have an image at the very beginning of your posts then you should know that people expect to access your post by clicking on the image (I tested this with CrazyEgg).

That’s why I came up with the Linked Image plugin. This little plugin does just that, it takes the first image in your post and links it to the post itself. Everywhere but in the post page.


Linked Image 1.0


  1. Download the plugin and expand it.
  2. Copy the ‘first-image-permalink.php’ file into your plugins folder (wp-content/plugins/).
  3. Login into the WordPress administration area and go to the Plugins page.
  4. Locate the First Image Permalink plugin and click on the activate link
  5. That’s it

Known Issues

  • The plugin doesn’t currently work if the first image is already linked and may render unexpected results.
  • Smileys get linked too


Support further plugin development by making a small donation:



  1. @asian beauty talk: If you’re able to edit the plugin file (linked-image.php) then all you have to do is locate the part that says <a href=”‘.get_permalink().'”>$1</a> and change it for <a target=”_blank” href=”‘.get_permalink().'”>$1</a>

  2. Only one question…

    If I add the image to the post trought the image uploader on WP2.5+, can the plugin retrieve the thumbnail of the image generated by the image uploader instead the image itself?

    I wanted to do this long time ago, and I don´t know that if this plugin capable of this.

  3. Nice and simple.. Would make sense to implement the filter in “the_excerpt”, too. I’ve also the one problem that smiley-pictures are linked.. To avoid this you have to put something like this in the “if”:
    $content1 = preg_replace($searchfor, $replacewith, $content, 1);
    $smiley = substr_count($content1, ‘wp-smiley’);
    if (!$smiley) $content = $content1;

  4. Sorry, my code sucked 😉 But when you replace the $smiley-line with
    preg_match ($searchfor , $content , $smileys);
    $smiley = substr_count($smileys[0], ‘wp-smiley’);
    it should work.. though I guess there are better ways to do this 😉

  5. @Jaspal Singh: You would replace the “1” in this line: “$content = preg_replace($searchfor, $replacewith, $content, 1);” for a 3. Like: “$content = preg_replace($searchfor, $replacewith, $content, 3);”

  6. this is pretty cool. Btw, can it also capture the post title to be the image caption and alt tag?

    Thanks and hope to see more improvement.

  7. Very nice plugin that helped me alot!
    Question: How can I change the Code to exclude certain categories of the function “wpguy_linked_image”?

    Greetings from Switzerland

  8. Hi
    Just found the right Code to fix what I asked in the question above:
    I changed “if (is_single() === FALSE)” into “if (is_single() === FALSE && in_category(7) === FALSE)” — so, if a post is from category ‘7’, the linkwrap does not appear.
    Greetings from Switzerland

  9. Thanks for the plugin. Great Idea. I can’t believe wordpress does not have this as an option by default.

    If an image is already linked this plugin causes 2 links to wrap the image, which can cause issues in different browsers. I’ve added a simple check to see if the image is already wrapped in an anchor tag, and if so the plugin will not add the permalink. Granted, its not the perfect solution but its a start.

    function wpguy_linked_image($content){
    $searchfor = ‘/(]*/>)/’;
    if(preg_match($searchfor,$content)===1) {
    $searchforLink = ‘/(]*/></a)/’;
    if(preg_match($searchforLink,$content)===0) {
    $replacewith = ‘$1‘;
    if (is_single() === FALSE){
    $content = preg_replace($searchfor, $replacewith, $content, 1);
    return $content;

    You could also use strpos() to check to see if ‘<img’ <=8 in the content, but theres a little more room for error there 😉

  10. In there any way of excluding certain images? I use the Add to Any plugin and the image turns into a link to my article if it’s within the threshold, instead of opening the Add to Any menu.

  11. Doesn’t work without flaws on 2.6.2 WP

    here’s the error on the single.php page

    Fatal error: Call to undefined function similar_posts() in C:InetpubwwwrootExhd.comwp-contentthemesflexaircustomsingle.php on line 46

  12. Elegant and simple. That’s exactly how any good blog should work (especially a recipe blog). I’ve had it set to always link to href=”” which would essentially just refresh the page which is fine on the page itself but annoying on the index if you want to get to the actual post. Thanks for a great plugin, works like a charm!

  13. Doesn’t work without flaws on 2.6.2 WP

    here’s the error on the single.php page

    Fatal error: Call to undefined function similar_posts() in C:InetpubwwwrootExhd.comwp-contentthemesflexaircustomsingle.php on line 46

  14. Do you know how I can filter out pages from this plugin? I’m having to put a header banner because things like an rss image will get linked too. I haven’t worked out in the code how to edit it so that it only works for pages. Do you know anything?!

    • To filter out pages from this plugin, just add !is_page() inside the if conditional statement.
      if (!is_single() && !is_page()){
      $content = preg_replace($searchfor, $replacewith, $content, 1);

  15. Thanks for the plugin. There is a little problem, it doesn’t work on categories, tags.

    Can you please help. This is a great plugin.

Comments are closed.