Get in touch with me Let's build something great.

WordPress Plugin: Comment Images Embedder

From December 8th, 2007 | 73 Comments
It’s rather common for a WordPress user to ask how visitors can add images to their comment. It’s never been an easy task… until now.

There are 2 versions of this plugin available, differing in features.

Premium Version

If you would like to give your visitor the ability to upload images along with their comment, I have developed a separate WordPress plugin that accomplishes that.

This plugin is now available for purchase online. It costs $97 and will be sent to you electronically immediately after you purchase it.

Why isn’t it free? It is a highly customized solution. It took a long time to develop and you’re also paying for my time.

Free Version

This will allow your visitors to embed an image that is already hosted somewhere on the web. All they have to do is add the link to the image and it will appear inline with their comment.

Download

wp-comment-images.zip

Installation Instructions

  1. Download
  2. Unzip
  3. Upload the plugin file to the wp-content/plugins of your website
  4. Activate via the Plugins page of the WordPress administration

Usage

A link should appear below the comment form, allowing the users to link to an image. Once they input the URL for the image and click OK, the appropriate markup will be added to their comment.

Donate

Do you find this plugin useful? If so, please consider donating to show your appreciation. Your contribution goes to make sure I can maintain and develop more projects. I will greatly appreciate your generosity. Thank you! Smile!

73 Responses

  • December 13, 2007 at 6:21 pm

    Three possible minor improvements to your plugin:

    (a) instead of the “you can add images to your comment” text appearing after the “submit” button and the “notify me of responses to this post” checkbox, and in my case also after the cocomment ‘cocobar’ which appears directly under the textarea,
    can yours be inserted directly under the “code allowed” line, above the textarea?

    (b) enable multiple image insertion “one image per line”, so if I have a collection I can copy and paste them all in one step

    (c) users can already right-click images and select “copy link location” and then paste that into the comment plugin, but for most people that requires too many clicks and scrolls. In Excel and OpenOffice, there is “Paste Special” which allows you to choose if you want to paste the text or the link (…). Can something similar be done on the web?

  • Trevor Fitzgerald
    December 14, 2007 at 1:04 am

    Jonathon,

    Thanks for the comment. You’ve got some good ideas…

    (a) Not all WordPress themes use the “allowed tags” code above the comment box. It’s something that’s hardcoded into each template. You could hard code the text into that place, though, so the “add image” link is above the comment box.

    (b) It’s possible but probably not useful for many people. It’s a good idea but I’ll leave it out of any future releases.

    (c) I don’t think so, no. The comment form is just a simple text input. It can’t be used like an advanced text editor.

    Thanks!

  • chris
    January 30, 2008 at 11:49 pm

    hey, great plugin!

    Im new to php and was wondering which php file calls the embed_image_instructions function? I wanna put the upload image text above the comment box instaed of below it.
    Thx

  • chris
    January 30, 2008 at 11:54 pm

    ah i found it
    in the comment.php for my theme it calls
    ID); ?>

  • chris
    January 31, 2008 at 12:00 am

    php do_action(‘comment_form’, $post->ID);

  • Trevor Fitzgerald
    January 31, 2008 at 12:15 am

    Chris,

    That’s the one! If you want it above the comment box, you’ll have to manually edit the theme. There is no WordPress ‘hook’ that allows a plugin to place it there.

    Thanks!

  • Paul
    January 31, 2008 at 9:58 am

    Love your plugin!
    Had a thought though. Instead of putting the image right in the comment, what about adding a link that would show the image in a lightbox? I have been trying to get it to work, but without success. The link would have to look like this below for it to work.

    <a href=”URL to image” rel=”lightwindow”>Link Name</a>

    Any thoughts as to how to get you script to put the above out.

    You would also need the ms_lightwindow plugin for this to work.

    Thanks for your thoughts

  • Trevor Fitzgerald
    January 31, 2008 at 12:00 pm

    Paul,

    That’s a very good idea! I’ve just recently become aware of lightbox and would love to use it in this plugin.

    I will add it to my list of things to do and make it an option in the next release. I will work on it a bit this weekend and email you my results.

    Thanks!

  • Paul
    January 31, 2008 at 12:46 pm

    Here is a one of the lightbox’s out there.

    http://www.stickmanlabs.com/lightwindow/

    This site has awesome instructions as well as how-to’s
    This lightbox can do much more than images. Can load just about anything you can think of, much better than most of them out there.

    I look forward to your results. Thanks, Paul

  • Trevor Fitzgerald
    February 2, 2008 at 12:34 am

    Paul,

    All that’s necessary to make lightbox (or other) work is the following:

    Click here for the instructions!

    Good luck and let me know if it works!

  • Paul
    February 2, 2008 at 11:07 am

    That did not seem to work. Although that might be some of the script that needs to be added. I think the following line needs to change as well.

    document.getElementById(‘comment’).value = document.getElementById(‘comment’).value + ‘[img]‘ + URL + ‘[/img]‘;

    The script is adding the image to the comment box with the [img] tag instead of using the link tag that it needs. I would imagine that the img + URL + img would need to look like the link populated in the comment box.

    I could be way off but when I tried the new scripted, all I got was a fatal error.

    By the way, I think we are neighbors…I live in Canton, MI.

  • Trevor Fitzgerald
    February 2, 2008 at 11:29 am

    Paul,

    My mistake. I forgot to escape 2 characters in my code. This one will work (I tested to make sure!).

    http://wordpress.pastebin.com/f47dc089b

    This assumes you have lightbox or lightwindow already setup on your site. Change “lightbox” to whatever the image script wants. You don’t have to change anything else. The PHP code parses the [img] tags and will return the link with the rel attribute.

    P.S. Hey! I was just in Canton, too. Did some shopping at IKEA.

  • Paul
    February 2, 2008 at 3:39 pm

    Worked like a charm. I had to change the “rel” to class to get it to work with lightwindow. Thanks for all your hard work. Looks great and works great.

    Paul

  • Antonio
    February 8, 2008 at 12:34 pm

    Hi Trevor,

    I just enabled this plugin on a Wordpress blog, and the link didn’t show below the comments block.

    Is there something I can check on my blog to make sure that this is displayed?

  • Antonio
    February 8, 2008 at 12:43 pm

    I think it has something to do with my theme, as when I switch back to the default theme it works fine. What would I have to edit in my theme to have this displayed?

  • Trevor Fitzgerald
    February 8, 2008 at 12:43 pm

    Antonio,

    You can check to see if this piece of code exists in your comments.php file of your theme:

    < ?php do_action('comment_form', $post->ID); ?>

    ** Make sure there’s no space between that greater than sign and the question mark at the beginning.

    If it doesn’t, just go ahead and add it wherever you want the link to appear.

  • Antonio
    February 8, 2008 at 1:03 pm

    Thanks Trevor!

    I think the comment section is working, but I don’t think the actual code is being embedded into the head. Is there another function that should be called ti embed the JavaScript into the head?

  • Trevor Fitzgerald
    February 8, 2008 at 1:07 pm

    Antonio,

    There is no code to add to the head. I modified my own plugin to work with lightbox. That might be what you mean.

    The downloadable version of this plugin will insert the image directly into the comment so it’s visible inline.

  • Antonio
    February 8, 2008 at 2:01 pm

    Well,

    When I try to add an image, the link isn’t being embedded into the comment box. I’m not sure why

  • Trevor Fitzgerald
    February 26, 2008 at 3:47 pm

    Antonio,

    It is likely because of your theme. Try changing to the default theme to see if it works.

  • Tal
    March 7, 2008 at 9:02 am

    I would love to see the ability to upload an images as well as just using a link

  • Raffy
    May 13, 2008 at 9:04 am

    Hi Trevor

    Is your plugin still 97 Dollars???

    Greets

  • nicole
    June 1, 2008 at 6:37 pm

    hi there,
    I have added your plugin and the following code but nothing seems to work once i enter the image URL..

    ID); ?>
    (without the space)

    I have it on http://thepetbarn.ignitionmedia.info/pet-stories. Can you please assist as to what I have done wrong or need to change.

    thanks very much

  • nicole
    June 1, 2008 at 6:44 pm

    Futher to my comment above, I have my comments function on a page, not post. Will this effect it?

    I changed my theme to the default but then there was no contact form on this page at all.??

    please help!

  • Trevor Fitzgerald
    June 2, 2008 at 11:52 am

    Raffy,

    Yes, the plugin is still available. I will be setting up a shopping cart shortly so that it can be easily purchased. Thanks.

  • Trevor Fitzgerald
    June 2, 2008 at 11:58 am

    Nicole,

    Your in your website needs an “id=’comment’” in order for it to work. The fix is quite simple. Just open up your theme’s comments.php, find:

    <textarea name=”comment” cols=”50%” rows=”8″>

    and replace with:

    <textarea name=”comment” id=”comment” cols=”50%” rows=”8″>

    Good luck!
    P.S. I really like your site!

  • Jon Hickman
    June 11, 2008 at 2:27 pm

    Trevor – are there any reference sites showing where the paid for version is installed? Could be just the thing for a project I’m working on.

  • Sean
    June 25, 2008 at 2:00 am

    Hi, maybe I’m stupid, but could someone please advise how I “install” the plugin? My site is hosted at Wordpress, so I don’t have any installation files.
    Thanks
    Sean

  • Trevor Fitzgerald
    June 26, 2008 at 11:17 am

    Sean, The plugin is only for self-hosted versions of WordPress. You can’t use it on WordPress.com.

    -Trevor

  • nichard
    July 6, 2008 at 8:44 am

    hi there,anybody who knows how can i have(upload and download images)on my website.like visitors can share there photo and download some images from my site.www.nichportrait.com.need some help thnx

  • Seo
    July 9, 2008 at 7:58 pm

    Well some like this way, Buy I think you should consider the another side of the toppic too. Thanks

  • James
    July 25, 2008 at 11:51 am

    test post please delete if you like Smile!

  • Matt
    September 8, 2008 at 2:03 pm

    Looking at the previous post, looks like it imbeds the link to the imag, not the image.

  • Trevor Fitzgerald
    September 8, 2008 at 2:05 pm

    Matt,

    I changed it so that it only provides a link. It can be easily configured to show the actual image, too.

    Trevor

  • J G Karthik
    September 19, 2008 at 2:30 am

    I need image upload through image search

  • Roland
    October 6, 2008 at 2:19 pm

    “I changed it so that it only provides a link. It can be easily configured to show the actual image, too.”

    Hello, I’m trying to get this to work, I changed the line with this one:

    $content = preg_replace(‘/\[img=?\]*(.*?)(\[\/img)?\]/e’, ‘”” . basename(“$1″) . “” . basename(“$1″) . ““‘, $content);

    It is showing the actual picture and the lightbox effect works but there are also 2 hyperlinks, 1 above and 1 below the picture. I’m don’t understand php very well so could you please help me with this? Thanks

  • Trevor Fitzgerald
    October 6, 2008 at 6:38 pm

    Roland,

    I sent you an email hopefully answering your question.

  • James
    October 16, 2008 at 8:22 am

    I am interested in the concept…but would thought that you would provide a model/example of the “picture in the comment”. If you could do this and let me know, I may be one step closer to a purchase.

  • Michael
    October 30, 2008 at 12:40 pm

    is there a way to limit the size of images posted in comments?

  • Andy
    December 26, 2008 at 1:48 am

    Hi Trevor,

    Nice plugin. But I have the same question as Michael:
    “Michael
    is there a way to limit the size of images posted in comments?”

    Users can upload pictures of any sizes, which is not good. Is it anything I can do to limit the size?
    Thank you.

  • Andy
    December 26, 2008 at 10:30 pm

    Hi Trevor again,
    Thank you for your reply.
    I am not a pro, please let me know what should I change in wp-comment-images.php to resize the pictures to certain size.
    Thank you.

  • DoZ
    January 3, 2009 at 4:17 am

    On your free plugin it could be great to show the ‘publish image link’ only to subscribed or admin users…
    Is it possible?

  • Dameian
    January 16, 2009 at 12:01 pm

    Hi Trevor. I just purchased your quite nifty comment image uploader script and wanted to report a weird quirk with it. The $upload_path variable was not able to properly define itself on my host. It kept inserting an erroneous portion of the server path into itself that didn’t belong. It repeated the beginning /usr/ portion of my server path after the domain name. So instead of…

    /usr/accountname/domainname.com/wp-admin/uploads

    I was instead getting the incorrect…

    /usr/accountname/domainname.com/usr/wp-admin/uploads

    …for some odd reason. I was able to rectify this by hacking your code a little (just defined it as /wp-admin/uploads which worked fine), but it is something that you might want to include in documentation for others just in case.

  • Trevor Fitzgerald
    January 16, 2009 at 6:13 pm

    Dameian,

    Thank you very much for pointing that out. I will see if I can’t change the code to make it more universal.

    Enjoy the plugin and let me know if there’s anything else.

    Thanks,
    Trevor

  • ari
    February 24, 2009 at 8:26 pm

    Hi Trevor,

    I emailed you this question but thought it might be better for it to be public. Are there any security issues/risks with this plugin (i.e. someone uploading a virus)?

    thanks!
    ari

  • Trevor Fitzgerald
    February 24, 2009 at 8:31 pm

    Ari,

    Great question. The plugin takes precautions to make sure that the uploaded content is indeed an image. Security is always a primary concern whenever I am developing a plugin. I made sure that this plugin does not open up your blog to any harmful exploits.

    Thanks for the question,
    Trevor

  • March 3, 2009 at 4:26 pm

    Спасибо за статью.. Актуально мне сейчас.. Взяла себе еще перечитать.

  • Milan
    March 15, 2009 at 5:56 pm

    I don’t want to write about this plugin but rather about something I saw in source code of this page.

    You use jQuery from their site, but instead you should use it from Google AJAX Libraries API, as it is recommended (and used) even by JQuery (also see for example latest release, where they also recommended this)). By this you are making bill to them, instead of free solution from Google.

    And you shouldn’t use packed version, but instead minified one, see why.

    Cheers!

    (p.s. install Subscribe to Comments plugin for easier comments replis tracking ;) )

  • Trevor Fitzgerald
    March 16, 2009 at 10:55 am

    Milan,

    Thanks for the info. Those were good reads. I have changed the code on my site. Thanks for bringing that to my attention. I’ll make sure I use it correctly on other sites, too.

    Thanks!

  • RaiulBaztepo
    March 28, 2009 at 6:17 pm

    Hello!
    Very Interesting post! Thank you for such interesting resource!
    PS: Sorry for my bad english, I’v just started to learn this language ;)
    See you!
    Your, Raiul Baztepo

  • andy
    April 6, 2009 at 2:14 pm

    As others have stated before, is there any way to limit the size of the pictures? or show just the thumbnails of the picture?

    I am using the free version. Thanks.

  • Trevor Fitzgerald
    April 6, 2009 at 7:02 pm

    Hi Andy,

    That is not currently an option in the free version. Although it is on my list for the next version!

    Thanks!
    Trevor

  • Jim
    May 19, 2009 at 9:09 am

    Hello Trevor,
    New to wordpress and PHP, but I have a question about your free version of your plugin. Can I have people add pictures to their comments to my blog, or only pictures VIA url?
    Thanks in advance,
    Jim

  • Trevor Fitzgerald
    May 19, 2009 at 11:04 am

    Hi Jim,

    With the free version, your visitors will be able to add an image that is already hosted somewhere on the web. All they do is insert the URL where that image is located.

    With the premium version, they would be able to add an image from their own computer.

    Hope this helps,
    Thanks!

  • Patricia Reszetylo
    May 24, 2009 at 3:14 pm

    Thanks, this looks very useful! I’ve downloaded the free version, and will be testing it. =)

  • 2Φ3Σ27Φ (\)λ√λ22Φ
    June 30, 2009 at 1:37 pm

    Great plugin!

    I got the paid version and it ROCK’S, the setup is a little bit on the advanced side (for a semi noob like me), but Trevor stuck with me untill i got it working just right.

    Thank’s Trevor, I wish Dell, Compaq, HP, Gateway, etc… had customer support this good.

    Check out my site and see it working @ Zacoalconet

  • Tom
    August 18, 2009 at 10:49 am

    Is it possible to turn off the light-boxing?

    Thanks,

    Tom

  • Matt
    August 19, 2009 at 8:18 am

    Do you have any experience with this working with the thesis theme? I just want to make sure it is good with wordpress 2.8.4 and thesis 5.1 before I buy it.

    Thanks

  • sam
    August 21, 2009 at 3:00 am

    Trevor,

    Can your paid version deal with non-image uploads, such as word files? I am considering purchasing but need to know if this is possible as my site requires the option to upload different file formats, particularly word or pdf files?

    thks

    sam

  • Eric
    August 29, 2009 at 9:06 am

    Still waiting on an answer for a question that was asked in December 2008:

    Is there a way to limit the size of uploaded images?

    Even something as simple as a css modification?

  • Trevor Fitzgerald
    August 30, 2009 at 8:22 am

    Tom, Yes the lightbox effect can be disabled.

  • Trevor Fitzgerald
    August 30, 2009 at 8:22 am

    Matt, Yes everything should work well with the Thesis theme.

  • Trevor Fitzgerald
    August 30, 2009 at 8:23 am

    Sam,

    By default, the plugin only accepts image files. Please contact me directly to discuss allowing other file types since it will require minor customizations.

  • Trevor Fitzgerald
    August 30, 2009 at 8:30 am

    Eric,

    The plugin resizes all uploaded images so size should not be a problem. If you still require size restrictions, please contact me directly so I can try to help you out.

  • Patrick
    October 25, 2009 at 7:25 am

    I resize all my Images via CSS, it’s the simplest way and you can separately choose which size the have if you setup rules for each the blog page and the comment page.
    Here’s the CSS you need:

    max-width: 515px;
    width: expression(this.width > 515 ? 515: true);

    __________________________________________________________

    I really hope Trevor comes up with a setting/setup page to deactive certain parts of the plugin.

    • I don’t need the resizing via phpthumb
    • I don’t want a separate Lightbox just for my comments (setting up my choice of Lightbox globally -not just for comments- seems more convenient to me)
    • But what I obviously like to keep is are the “rel=”lightbox” tags, so that I can use/customize them wo work with other lightboxes (At the moment I get two lightboxes displayed in the comments)

    Anyway nice plug-in… I just need some advise how to tweak it.

    Cheers,
    Patrick

  • Chris Countey
    October 26, 2009 at 10:36 am

    Trevor,

    I’m using your plugin at http://pricelessimprinters.com/blog and I wanted to know if there is a way to control the size of the image within the code. I tested it and linked to a large image that was HUGE. Thanks.

  • Chris Countey
    October 26, 2009 at 10:40 am

    Nevermind, I found this line in the source and added the “width” parameter. Thanks for the plugin.

    [code]
    // Accepts 2 formats:
    // 1.) [img]http://image.gif[/img]
    // 2.) [img=http://image.gif]
    function embed_images($content) {
    $content = preg_replace('/\[img=?\]*(.*?)(\[\/img)?\]/e', '""', $content);
    return $content;
    }
    [/code]

  • Val
    December 1, 2009 at 3:33 am

    Hi Trevor,

    I just upgraded that plugin to 1.4 and it didn’t show in my plugin page and of course it was disappear from my wordpress.
    I tried to erase it and install again.
    When I tried to activate it, there is an error, it said something like “it has no valid header”.

    Please advise, thanks.

  • December 1, 2009 at 6:23 pm

    Hey there Trevor. This plugin has just broken on our WP 2.8.6 install. First it just disappeared and all the embedded links became non-functioning, now I get this error when I try to reinstall it:

    “The plugin does not have a valid header.”

    Any ideas? Thanks!

  • Trevor Fitzgerald
    December 1, 2009 at 7:56 pm

    @Val & @Trollcats,

    Thank you for reporting the issue. I just finished taking a look.

    I upgraded the plugin to version 1.5. You can download it here: http://wordpress.org/extend/plugins/wordpress-comment-images/

    Everything should be back to working. Sorry for the inconvenience!

  • December 20, 2009 at 3:31 am

    I was pleased to find your plugin but unfortunately it’s not functioning properly on my site. The link appears on the comment box, when clicked it brings up the box to enter a URL but when clicking OK, the box disappears and no image appears in the comment,

    Appreciate any suggestions on how I might resolve this.

    • Trevor Fitzgerald
      December 21, 2009 at 6:54 pm

      Hi Chris,

      Does anything show up in the comment box after entering the image URL? It should add “[img]http://…image.jpg[/img].

  • January 28, 2010 at 3:01 pm

    Trevor,
    I updated the theme, put the code in the same way as before and now it works. Let me say that your plugin is very cool! I didn’t even know about the lightbox feature when my client purchased it. VERY COOL. Thank you!

Leave a Reply

Are you on Twitter? You can also comment via Twitter by clicking here.

Please enter your name, e-mail address, and comment. Thank you!
Twitter

Twitter Updates

  •  

You should follow me on Twitter here.

RSS

From The Blog

03Mar

Introducing Earthly WordPress Theme

Based on my first WordPress theme, Crispp, Earthly incorporates a color scheme designed for sites that require an eco-friendly or earthy theme. Features 100% Free Consistent styling across all major …

Continue Reading…

28Dec

YouTube Resizer jQuery Plugin

The jQuery YouTube Resizer plugin automatically resizes embedded videos to fill up the entire content space. It expands the video if the content area is larger and contracts if it is smaller. My first…

Continue Reading…