I need a way to create a custom field that will let me pick an image from the media gallery. How do I do that?

The custom field should have a button that when clicked will take me to the media gallery and place the src destination url within a input text box.

looking for a plugin or online tutorial and I'm having little luck.


4 Answers 4


A few weeks ago I added a feature similar to Magic Fields.

Here's the github project. The most important thing is in this file: js/custom_fields/media_image.js


By using one of the plugins that already do this:



This to me sounds like the post_thumbnail feature in WordPress. It will add a box on the right hand side, below the tag box. By default the box displays a link "Set featured image".

When you click on it the media gallery popup opens and you can pick a picture you have previously uploaded to the post as the featured picture.

You can then use:

if (has_post_thumbnail()) {

in you theme to display the featured picture.

To enable post_thumbnail you just need to add:

add_theme_support( 'post-thumbnails' );

to your theme's function.php


To answer your question a bit sideways, are you open to an alternative? I suggest adding a photo to a post, filing the post under a specific category for your images, and maybe, depending on your needs, adding a text-only custom field to retrieve that specific image.

$image = get_posts('cat=the_category&meta_key=the_key&meta_value=the_value');
foreach($image as $img){
    //whatever your markup is...
    echo '<p>'.the_content().'</p>';
   echo '<p>'.$img->post_content.'</p>';

Just a thought...

  • interesting, might take a look at that idea. However, I have seen the concept I'm talking about used with audio for a podcast I run. It may be that I need to look at their code and see how they approached the issue.
    – Kevin
    Commented Aug 20, 2010 at 2:38
  • I'm in the process of re-developing my business website in WordPress, and I currently have a few images being rendered to the page this way. Unfortunately, I load about 10 images into a slideshow. Just today I had the idea to load all ten images into the same post and only have to call one post instead of ten. Now to go back and clean up the code!
    – kevtrout
    Commented Aug 20, 2010 at 3:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.