Hello. My name is Noemi Millman, and Triopter is my web development agency. We handcraft beautiful, dynamic websites.

See what I can do for you.

Noemi Millman: Triopter: Announcing NKMImageField - A Custom Image Field Plugin for Wordpress

Announcing NKMImageField – A Custom Image Field Plugin for WordPress

UPDATE 12/15/09: With the release of version 0.6, I’m closing comments on this post. Please continue discussion over at the release announcement post.

UPDATE 2/9/09: This plugin has been updated to version 0.3.1 and is available for download from the WordPress site.

Have you ever wanted to add a custom field to a WordPress post or page that contained an image URL — for instance, to use in a template?

You’ve probably noticed that it’s a real pain in the rear: you have to find the URL for the image and then copy and paste it into a field. If you have non-technical users managing the site, chances are they have a lot of trouble with this process.

You’re not the only one who’s been frustrated.

Well, good news. I’ve just released a plugin that allows you to use the WordPress 2.5 media gallery to build custom image fields with a friendly graphic interface. It’s now available for download, and should be hosted on the WordPress site shortly.

Important Update 9/26/08: Versions prior to 0.2.3 have an installation bug that causes any attempt to create a new field to fail. Please download and install version 0.3.1 instead.

  1. COMMENT: by olivier, September 25th, 2008

    hi Noemie

    thanks for sharing this plugin !
    I’ve installed it on a 2.6.2 version, there was no errors, anyway when trying to add a field I get this error :

    Unknown error adding or editing field.

    and there’s no field added

    Any hint ?


  2. COMMENT: by Noemi Millman, September 26th, 2008

    olivier – Thanks for trying out the plugin, and for your feedback! I haven’t tested on 2.6.2 yet, but I’ll definitely see if I can track down the error you encountered. Can you tell me anything about what you tried to do (e.g. the name and description you used for the field you tried to add)? Also, do you know whether your server uses PHP4 or PHP5?

    EDIT: You’ve uncovered an installation bug — thank you! It’s now fixed, and version 0.2.3 should work properly.

  3. COMMENT: by Leonaut.com, September 26th, 2008

    NKMImageField – A Custom Image Field Plugin for WordPress…

    NKMImageField provides an easy graphical interface for inserting image URLs from the Media gallery into custom fields….

  4. COMMENT: by erez, November 21st, 2008


    I’m using wordpress 6.3 (in french). When I try to use your plugin it insert an img tag into the article instead of puting the image name into the image field.

    What’s wrong?

    Thanks for your answer and great idea.

  5. COMMENT: by Noemi Millman, November 22nd, 2008

    Hi erez — thank you for pointing out that bug. It will be fixed in the next release, which will come some time after Thanksgiving.

  6. COMMENT: by Leighton, January 25th, 2009

    Hi Noemi

    How are you getting on with the bug fix? I’m using your plugin in WordPress 2.7 and find that the image url is inserted in the post and not the image field.

    Hope you can get it fixed soon, because this is a real must have for developing WordPress as a CMS

  7. COMMENT: by Noemi Millman, January 25th, 2009

    Thanks for reminding me. I’ve been absolutely swamped with work since about Thanksgiving, but hopefully can get around to it in February or March. Apologies for the delay.

  8. COMMENT: by foxman, February 8th, 2009

    Hi, this is the dreaming plugin must of WP users looking for, so thanks for sharing it,
    i use the WP 2.7, and the plugin activate with no arror, but it dont insert the the link in the img field.
    so i hop it will be compatibl with this version of WP.

  9. COMMENT: by N, February 9th, 2009

    I’m also running into the same problem with WP2.7 and the plugin. The image is getting inserted into the main body for the post always. Looking forward to a WP2.7 compatible version, thanks!

  10. COMMENT: by Noemi Millman, February 9th, 2009

    I’ve been completely overwhelmed by work lately (in a good way, at least), but I’m hoping to get to this very soon. Thanks for your patience, everyone!

  11. COMMENT: by BalGHA, February 12th, 2009

    why not to go and see this theme, it use many photo uploader fields, and it work perfectly
    login and passe : demo
    I hop i help you to build another one.
    Download the theme : http://www.box.net/shared/9qey7ehnom
    Now you have the source file ;)

    good luck

  12. COMMENT: by Juissi, February 12th, 2009

    Can i use this in my sidebar?

    Could you give me a template php script for example.

    I just want to show a different specific image on every page & post in my sidebar, and this plugin could be great, but i just can’t get it to work. I get an error every time..

    Using WP 2.7.1

  13. COMMENT: by Noemi Millman, February 12th, 2009

    Absolutely. Say you have an image field with the name “myfield”. You’d use the following code to display the image in the template:

    <img src="<?php echo get_nkm_imageurl('myfield'); ?>" />

  14. COMMENT: by Brain Gorski, February 27th, 2009


    Thank you so much for this sweet plug in. It works perfectly!

  15. COMMENT: by Andy Macaulay-Brook, February 28th, 2009

    Odd – the get_nkm_imageurl() function doesn’t produce anything for me. I can get the right values out by using get_nkm_imagefields() but it’d be nice to understand why the simpler function doesn’t return anything.

  16. COMMENT: by Noemi Millman, March 1st, 2009

    Andy, are you passing the name of the field to get_nkm_imageurl() as a parameter, as in the example above? If it doesn’t receive a valid fieldname as a parameter, it won’t return anything.

  17. COMMENT: by malte, March 6th, 2009

    Hello! thx for your plugin! ;)
    I found some bugs lurking in the functions

    there’s an ‘l’ missing in line 219 and 236,
    and both functions need to initialize the nkm_field object with the post ID to produce output.

    function get_nkm_imagefield($fieldname) {
    global $post, $nkm_field;
    if(!is_a($nkm_field, ‘NKMImageField’)) {
    $nkm_field = newNKMImageField();
    foreach($nkm_field->fields as $field) {
    if($field['name'] == $fieldname) {
    return $field;
    return NULL;

    function get_nkm_imageurl($fieldname) {
    global $post, $nkm_field;
    if(!is_a($nkm_field, ‘NKMImageField’)) {
    $nkm_field = newNKMImageField();
    foreach($nkm_field->fields as $field) {
    if($field['name'] == $fieldname) {
    return $field['value'];
    return ”;

  18. COMMENT: by Mike, March 9th, 2009

    That’s odd, I have had the same problem as Andy and I was sure that haven’t overlooked something.
    But I found that when I call


    before calling


    in the same run, the latter poops the requested url. Anyway, thanks for the plugin!

  19. COMMENT: by Noemi Millman, March 9th, 2009

    malte and Mike — thanks for tracking down those bugs! I’ll take a look at that as soon as I get a free minute.

  20. COMMENT: by Jonas, March 12th, 2009

    Thanks for a great plugin!

    Is it possible to use this for other media also? I would like to use it for uploading of music-files but it doesnt seem to work when I choose a mp3-file instead of an image.

  21. COMMENT: by Noemi Millman, March 12th, 2009

    Jonas — I haven’t tried to get it to work for other media, but I’m reasonably confident it could be done. I’ll add it to the list of things to investigate.

  22. COMMENT: by Julian Moller, March 12th, 2009

    Hi Noemi,
    Thanks for the plugin, had to hack a wee bit to get some of the functions to work – see above guys comment with code. But all good – found a way to fix the “inserting into post instead of field issue” – but it was a hack in \wp-admin\includes\media.php @ line 410 – I set $_POST[send] to $_POST[nkmsend] (and unset $_POST[send]) to prevent WP inserting media into posts (only works in my situation because I dont allow images in posts, so not suitable). Hopefully that points you in the right direction for your future bugfix. Also note that it only occurs when you use the ‘insert into post’ button that appears AFTER you have uploaded an image, if you use the insert into post after selecting an item from the media gallery there is no problems

    However, I recently moved the wp install over from old dev hosting to new dev hosting. And now upon clicking the ‘insert into field’ button next to a field – the screen shows the loading bar for the flash uploader then just exits. Meaning that the uploader doesnt even show up! I have tried reactivation, deleting dbtables remaking fields etc with no luck.

    Any ideas?

  23. COMMENT: by Jonas, March 13th, 2009

    Has anyone found a workaround for the bug which inserts the img tag into the article instead of putting the image name into the image field?

  24. COMMENT: by Noemi Millman, March 13th, 2009

    Julian and Jonas — The flash uploader does not currently work — it will result in the URL being inserted into the post body. However, the plugin has been tested with the browser uploader.

    If you are experiencing this problem with the browser uploader, could you please let me know what browsers and versions you’re using so I can troubleshoot further?

  25. COMMENT: by Alex Parish, March 19th, 2009

    Fantastic plugin. Has saved me so much time, thank you!

    A problem I have come across is with line 28 in NKMImageField.class.php:

    if(count($this->fields)) { return; }

    I can see you have included this to stop unneccessary database queries but I’ve found that it can cause problems. For instace when I want to display custom image fields on a category page this portion of code will stop the plugin from sourcing images from the 2nd, 3rd, 4th.. and so on posts of the page. For now I have commented this line out so category pages are supported but I understand this isn’t efficient as there will be a query per post. Have you thought about supporting category pages?

  26. COMMENT: by Noemi Millman, March 23rd, 2009

    Oh, good catch about the category pages. Added to the to-do list.

  27. COMMENT: by Dude, April 30th, 2009

    This is THE perfect plugin, i was really looking for this, and just for this.


  28. COMMENT: by Oszkar Horvath, May 13th, 2009

    Noemie – this plugin is just power of tower, can’t say how useful and sophisticated it is from the user’s point of view! THANK YOU!

    malte – the bugfix code you have posted here was awfully important to make it work, thank you for your effort to find the bug, resolve, and posting it here!

    I did some bugfixing and translation for WordPress Filter plugin, but I can’t say how good I feel when I see other people putting work into something for the good of others. Thank you guys!

  29. COMMENT: by Mael, May 28th, 2009

    OMG, I’m so sorry :(
    New try :

    Hello, here is a sample of what a non-coder like me think he have to do :

    <img src="" />

    Should this display an image ?
    I get nothing…

  30. COMMENT: by Noemi Millman, May 30th, 2009

    Mael — I’m sorry, it’s not clear to me what you’re asking. In order for an image to appear, you need to specify a path for the src attribute.

  31. COMMENT: by Mael, June 1st, 2009

    I can’t display code ! Here is what I wanted to show you, writed without the php declarations :

    The loop :
    php while (have_posts()): the_post();

    and within :
    img src=”php echo get_nkm_imageurl(‘myfield’); ”

    Then some content or else, and finish :
    php endwhile;

    Nothing appears in the src attribute with this code…

  32. COMMENT: by Noemi Millman, June 1st, 2009

    Are you using the actual text “myfield” or the name of your field?

  33. COMMENT: by Mael, June 2nd, 2009

    I use the name of my field. I called it “myfield” ;) !

  34. COMMENT: by Leighton, June 9th, 2009

    I’m having exactly the same problem as Mael – any pointers?

  35. COMMENT: by Noemi Millman, June 18th, 2009

    Mael and Leighton — it’s difficult to troubleshoot without details of your setup. What versions of WordPress and PHP are you using?

  36. COMMENT: by Mael, June 19th, 2009

    WP 2.7, php 5.2.6
    No other plugin, (local test site).
    custom theme (basic loop, header and footer, one widgertized sidebar).

  37. COMMENT: by Kaan, June 23rd, 2009

    Hi Noemie! Thank you for this great plugin! I’ve been using it a lot (had to tweak it myself a bit too, like described above, but that’s all good ;-)

    I think I’ve found a bug when scheduling a post. When a post is scheduled to be published in the future, the moment it is published the imagefields are cleared! This means I have to manually add the field s again (making the scheduling useless).

    Is this a known issue with a fix, or a complete new one? I would love to have a fix for this!

    Thank you a lot in advance!!

    greetings, Kaan

  38. COMMENT: by Noemi Millman, June 23rd, 2009

    That’s a new bug, Kaan — thanks for reporting it. I’ve added it to the list of issues to investigate as soon as I get a chance. If you want to try to fix it yourself before then, I think it may be related to how WordPress stores IDs of post “drafts”.

  39. COMMENT: by Leighton, June 30th, 2009

    OK – Similar to Mike’s post on March 9, 2009.

    I am using WP2.8 with PHP5 and find that you have to call the get_nkm_imagefields() function THEN echo the result of the get_nkm_imageurl($fieldname) function.

    When you do that is all works perfectly

  40. COMMENT: by Jazz, July 20th, 2009

    How does one do that? Can you give a code snippet for this? I’m sorry, but my php s*cks….

  41. COMMENT: by henk, August 18th, 2009

    Since i’ve updated to 2.8.4 the images don’t come up in the gallery anymore…

  42. COMMENT: by Noemi Millman, August 18th, 2009

    henk – sorry about that. I haven’t yet had a chance to test / troubleshoot in 2.8.4.

  43. COMMENT: by Brian Gorski, August 18th, 2009

    If you are having troubles with quick edits and with scheduling a post deleting the content you can updated your code to this. It will make it so when there is no post field for the images it does not do an update. Hope this help.

    Also I know for sure this is not the best way to do things. If someone with more php skill could take a crack at touching this up that would be great.

    function save_custom($post_ID) {
    global $wpdb;
    $post_id = (int) $post_ID;
    $vt = $this->controller->value_table_name;
    $keylist = array_keys($_POST);
    $hasImageKey = false;

    foreach ($keylist as $akey){
    $hasImageKey = true;

    $fields = &$this->fields;
    $vals = $_POST[$this->field_base];
    foreach($fields as $field) {
    $field_id = $field['field_id'];
    $value = stripslashes( (trim( $vals[$field['field_id']] ) ) );
    $value = $wpdb->escape( maybe_serialize($value) );
    $sql = “REPLACE INTO $vt (post_id, field_id, value) VALUES (%d, %d, ‘%s’)”;
    $result = $wpdb->query($wpdb->prepare($sql, $post_id, $field_id, $value));
    } // end foreach $fields

  44. COMMENT: by shawn, October 18th, 2009

    2 quick questions.
    1. does this plugin work with wordpress-mu 2.8.4a?
    2. am I right to assume that all the ‘fixes’ in the comments since february have not yet been applied to the download?

    Hoping this will work for me, been trying to figure out how to do this for days now.

  45. COMMENT: by Noemi Millman, October 19th, 2009

    Hi Shawn –

    Honestly, I have no idea whether the plugin works with MU. I’m not sure anyone’s ever tried it. Unfortunately, I haven’t had a chance to work on it in several months, so you are correct that the fixes have not yet been applied; nor has the plugin been tested on WP2.8.4. If you do decide to try it on MU2.8, please let us know how that goes!

  46. COMMENT: by AMB, November 20th, 2009

    This plugin is a cool idea, but honestly I think it’d make more sense if it used post-meta. Seems kind of like a kludge.

  47. COMMENT: by Noemi Millman, November 20th, 2009

    AMB: The first proof-of-concept I built of this plugin did use post-meta, but there were a few drawbacks — among those, that it was difficult to provide multiple named image fields per post, and that I had to do some processing that was ugly and probably not maintainable to get the right data in and out of the form. In the end I decided that using separate tables and not having to deal with those issues was a better approach.

  48. COMMENT: by Serge, December 2nd, 2009

    Hi Noemie

    I have a custom field called “image”. In this field the author should enter easily the path/name of a specific picture using the media library. Is that the idea of that plugin? If yes, I will have some other questions :-)

    Thanks for your feedback.

  49. COMMENT: by Noemi Millman, December 2nd, 2009

    Serge — yes, that is the basic idea of this plugin; however, I’m not certain whether it works with WP 2.8. If you do get it working, please let us know.

  50. COMMENT: by Arturo, December 11th, 2009

    Yes actually this plugin is great. However need some fixes. Most with the flash, and some cosmetics changes.

    This works on WP 2.8.6 (Didn’t try in WPMU)
    Here is the fixed plugin:


  51. COMMENT: by Bo, December 12th, 2009

    If you later on adds possibility of using the NextGen-Gallery it will be perfect for my needs.

  52. COMMENT: by steve, December 14th, 2009

    Is it possible to use this plugin functionality within my theme admin page instead of an article or website page?

    I was thinking of using this plugin within the theme admin to allow my users to select a page background image from the gallery instead of the classic way of having to upload an image directly, or pasting in the image code like most themes do.

  53. COMMENT: by Noemi Millman, December 14th, 2009

    Arturo — thank you for the update, but I am unable to download it to review the code or test it out. Is there somewhere other than rapidshare that you might be able to host the file?

    Bo, thank you for the idea. I’m a big fan of nextgen-gallery, so I’ll consider that for future development.

    Steve, there is probably a way to accomplish that, but this plugin specifically associates an image with a post or page. It does not have an interface for selecting an image outside a post/page context.

  54. COMMENT: by steve, December 14th, 2009

    @Noemi – I just read through all the code, and I can indeed see that nkmimagefield is completely dependent upon being in a page or post.

    Can I ask what you would charge to build a custom version that I could use within a theme admin, and what a timeframe for such a project would be?

    I’ve got to imagine that there has to be a way to call the gallery outside of a page/post. The only ‘issue’ I see, is obviously the saved data can’t be attached to a post meta table. Would probably work just as well using a table array within the theme itself to save the output?

    thank you

  55. COMMENT: by Noemi Millman, December 15th, 2009

    Steve: I’ll have to look back into the code to see what would be involved in putting together a theme admin version. May I email you an estimate in the next few days?

  56. COMMENT: by steve, December 15th, 2009

    Yes, email would be perfect. I am guessing you have my address in your admin.

    Thanks again!

  57. COMMENT: by Noemi Millman, December 15th, 2009

    Steve — you’ll be receiving an email shortly

    Arturo — I finally managed to download the file you provided. Thank you for the fixes. I’ll be incorporating the Flash fix in particular into the next release. Please let me know whether and how you’d like to be credited.

  58. COMMENT: by Noemi Millman | Triopter» Blog Archive » NKMImageField 0.6 Wordpress Plugin: Updates and Bug Fixes!, December 15th, 2009

    [...] evening working on my WordPress plugin, NKMImageField, fixing most of the bugs mentioned in the previous comment thread. The result is NKMImageField v0.6, which is now available for download from the wordpress plugins [...]

  59. COMMENT: by Noemi Millman, December 15th, 2009

    Please note: I’m closing comments on this post and moving discussion over to the announcement thread for version 0.6 (released today), which should fix most of the bugs reported above.