WordPress Guy

WordPress Guy designs and develops WordPress themes and plugins. WordPress Guy teaches you WordPress stuff.

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.

Download

Linked Image 1.0

Installation

  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

Donate

Support further plugin development by making a small donation:

donate

Comments

  • May 8th, 2008 at 11:24 am

    Thanks a lot for this pluging. Just downloaded, go to see how it works

  • May 8th, 2008 at 12:26 pm

    cool plugin
    it worked for me
    thanks a lot

  • May 8th, 2008 at 12:51 pm

    You’re very welcome. Please do not hesitate to contact me if you have any problem at all.

  • May 8th, 2008 at 1:11 pm

    hello man
    i need my link open in new windown,an ur teacher me to setup it??

  • May 8th, 2008 at 1:18 pm

    @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>

  • May 8th, 2008 at 2:35 pm

    Excellent, tks Wessley, works out of the box!

  • May 8th, 2008 at 3:17 pm

    does it works for older posts too?? Or it will work only for new posts??

  • May 8th, 2008 at 3:21 pm

    @Khamosh: Yes, it’ll work for older posts as well.

  • May 9th, 2008 at 2:57 am

    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.

  • May 9th, 2008 at 12:54 pm

    Downloading. Giving it a try. A very useful plugins if it works for me ;)

  • ... kann dies WP nicht, doch mit diesem Plugin - Linked Image , von Wessley Roche - geht es, wenn das 1. Bild kein Link zum großen Bild ...

  • May 9th, 2008 at 11:47 pm

    Great plugin.

  • May 10th, 2008 at 3:23 pm

    Awesome idea and great plugin! Thank you very much!

  • May 11th, 2008 at 8:44 am

    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;

  • May 11th, 2008 at 9:53 am

    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 ;)

  • May 11th, 2008 at 11:11 am

    @Andy: You’re right… I didn’t realize smileys would get linked as well. Thanks for the suggestions, I’ll try to fix this asap.

  • May 13th, 2008 at 6:55 pm

    hi. Thanks for plugin

    perfect.

    regards

  • May 18th, 2008 at 10:16 am

    can u pls tell me the coding if i want to make first three images as the permalink of the article …

    thnx for a wonderful plugin

  • May 18th, 2008 at 10:46 am

    @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);”

  • ... Linked Image- This plugin takes the first image in your post and links it to the post ...

  • June 1st, 2008 at 1:19 pm

    ... 3. Linked Image ...

  • ... Linked Image : pour lier la première image de votre billet au post complet ...

  • June 4th, 2008 at 7:02 am

    Excellent idea. Do you or anybody know if it conflicts with this plugin from Justin Tadlock? -
    http://justintadlock.com/archives/2008/05/27/get-the-image-wordpress-plugin

  • June 15th, 2008 at 3:11 pm

    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.

  • June 18th, 2008 at 6:56 pm

    @gofree: It could. Definitely something to consider for a future version.

  • ... Linked Image downloaden ...

  • August 12th, 2008 at 11:59 pm

    Thanks so much for this. Just spent an hour mucking around with another plugin and this one worked instantly.

  • Tracy
    August 13th, 2008 at 12:10 am

    Dude, I love the way your comments look. Mind sharing the css and comments.php file to get it that way?

  • August 19th, 2008 at 2:28 pm

    You are absolutely right! Images always have a visual attraction than the textual matter.

  • Markus
    September 10th, 2008 at 2:01 pm

    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

  • Markus
    September 17th, 2008 at 10:53 am

    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

  • ... View it here | Download 22) Linked Image- This plugin takes the first image in your post and links it to the post ...

  • September 23rd, 2008 at 10:42 pm

    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 ;)

  • September 23rd, 2008 at 10:45 pm

    err… yeah.. comments parsed the code strangely.. don’t copy and past the above! But I think you get the idea.

  • October 7th, 2008 at 2:49 pm

    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.

  • October 11th, 2008 at 9:42 pm

    YAY! I’ve tested 5 plugins of the same functionality, but neither worked for me except yours!

    Thanks a lot!

  • October 15th, 2008 at 5:29 am

    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:\Inetpub\wwwroot\Exhd.com\wp-content\themes\flexaircustom\single.php on line 46

  • October 15th, 2008 at 5:32 am

    False Alarm it works , I forgot to have my other plugin activated (Similar posts)

  • October 23rd, 2008 at 12:05 am

    Thank you so much for this Plugin. Wordpress should have this as default.

    Thanks

  • October 31st, 2008 at 5:39 pm

    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!

  • November 11th, 2008 at 11:56 pm

    Thank you, Thank you, Thank you!!!! Exactly what I was looking for and works perfectly!! Thank you, Thank you, Thank you!!!!

  • November 17th, 2008 at 12:56 pm

    Hi,

    I’ve set a higher threshold, which works fine for me on all pages except my forums http://www.ps3bloggen.se/forum where the register and login buttons link to the forum page instead of their respective links.

    So is there any way of excluding an entire URL and undercategory, like everything under http://www.ps3bloggen.se/forum?

  • December 11th, 2008 at 5:36 am

    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:\Inetpub\wwwroot\Exhd.com\wp-content\themes\flexaircustom\single.php on line 46

  • December 11th, 2008 at 5:37 am

    Thanks for a great plugin, works like a charm!

Your Comment