Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
WordPress Plugins
View all Guides


  1. Nevena says:


    I need to link my featured image of the custom post to external link. I tried this code, but when I click on image, it doesn’t go to link. What am I doing wrong?

  2. fynn says:

    this does not seem to work anymore with wp 4.2.2
    its not saving the entry

  3. Nuno says:


    Can we have a custom field on the image details pop-up ?

    Thank you

  4. Rihan says:

    Thank you for the great post..

    and can you help me how to add check box ( not text field )?? i try to change
    $form_fields[‘be-photographer-name’] = array(
    ‘label’ => ‘Photographer Name’,
    ‘input’ => ‘checkbox’,
    ‘value’ => get_post_meta( $post->ID, ‘be_photographer_name’, true ),
    ‘helps’ => ‘If provided, photo credit will be displayed’,

    and its not working

  5. Ellis says:

    This is great and just what I was looking for. However, I’d love to have those extra fields (photographer’s name, url) available in the “Image Details” window within the post Editor as well, can this be done?

  6. Andreas Morgta says:

    great tutorial, thanks alot for writing it.

    Unfortunately it isn’t working with the great plugin “Enhanced Media Library”:

    The bulk editor just loads and loads… :(

    Any idea how to fix that?

    • Jess Tura says:

      check your ending pair of the php tags.

      maybe do not copy line 48 at the above code as the plugin code from another tutorial has it already.

  7. test says:


    What code do I have to insert to make this show on an image within a post (not a featured image)?


  8. Domingos says:

    The fields are being displayed in the media upload, but the output is not showing up in any of my template files. I’ve added this code to my content.php but nothing is showing up:
    ID, ‘be_photographer_url’, true);?>

    Also tried with:

    I’ve also test it on the twentytwelve theme and there it’s also not showing up.

  9. James Murray says:

    Thanks for the tutorial. I’ve used it on my site and the custom fields work great – I just have a problem in that it screws with the modal menu. This means that when my users go to ‘Add Media’ in the post panel, they won’t see anything in the media library, won’t be able to set the default image etc. I’ve tried setting $form_fields[“custom_field”][“show_in_modal”] = false; but that doesn’t make a difference. It seems as soon as I mess with attachment_fields_to_edit I get this error.

    • James Murray says:

      Update on this – I was calling a jquery datepicker for one of my extra fields and this didn’t agree with the modal menu. Got around it by only calling the javascript when the url ends in action=edit – hope that helps if anyone else comes across this rare problem!

  10. Linus says:


    Really nice tutorial!
    In this case i’m using this for gallery purposes, where the user can add extra info. This info will be captured in the jQuery prettyPhoto later. The user should be able to use the same image in multiple albums (on different pages that is) but with different captions. So, i guess i have to make some logic that saves the values as a json string, where the first value is the page id number (not the attachment id number). How can i get that page (or post for that matter) id number, inside of this function?

  11. Patrik Illy says:

    thanks for article, is it useful. I have one question. I have set categories for media and i need to use filter by this categories in media uploader, ideally next to filter by media type… Is there any solution how to add select with used categories on this place?

    Thanks for reply

  12. Baylock says:


    Thanks for this neat trick.
    One question though: How would I put these news fields above some of the native ones?
    Let’s say I would like to add a field just after the “Caption” field…
    I tried to mess with the value in the “add_filter” but it doesn’t seem to change anything.

    Thanks for your help!

    • Editorial Staff says:

      Modify the priority numbers from 10 to 5.

      • Baylock says:

        As I said, that’s what I did with no success.

        In the meantime, I found a workaround:

        I unset the other fields like this:

        $image_size_field = $form_fields[‘image-size’];

        I declare the new fields by using your script and THEN I set the unset fields when needed like this:

        $form_fields[‘image-size’] = $image_size_field;

        This way, the “size” field (for instance), will appear after the two new fields.
        It did the trick.

        Thank you.

  13. Donna Fontenot says:

    Good stuff, thanks!

    Now, here’s an idea for another post. :) I’m a bit aggravated with the latest media uploader. When looking at images that we’ve uploaded within the post editor (as opposed to looking at images within the media admin section), the window no longer shows the file url of the image there. (We used to copy/paste that url into a custom field after uploading an image into a post). Now, we have to get out of the post edit screen (or open a new tab) and go to the media admin section, find the image, and grab the file url from that window, come back to the post, and paste it into a custom field. So, how about writing a post on how to display that file url in the media window WITHIN the post editing screen, like it used to have? I know I’d appreciate that post! :)

  14. Sacha says:

    Excellent code!

    But what if I need to display the gallery with the [gallery] shortcode, how can i tell WP to add my new custom fields?
    Any ideas?

  15. smattiza says:

    i apologize if dumb question but…i have added to functions.php but do not know where to place the echo code in order to display the credit under photos – esp. on home, category and single posts.  Would someone please help with any instruction.  Thank you very much.

    • wpbeginner says:

       @smattiza You can display the code in your single.php file, archive.php, category.php or any of those files. It needs to be displayed inside the loop.

  16. Editorial Staff says:

    Not sure why you are getting the error because we literally copy and pasted the code from our plugin file.

  17. EB says:

    I tried this — my first attempt at a plugin — and it wouldn’t activate. I got this fatal error. (Just FYI, my line 15 is = to your line 10): Parse error: syntax error, unexpected T_VARIABLE in /home/blackmom/public_html/wp-content/plugins/credit-and-courtesy-by-eb/photocreditplugin.php on line 15

  18. markus says:

    Thanks for your code! Any idé how i can add the tinymce editor to one of this inputs? 

  19. wpbeginner says:

    Hey Bill,

    We modified and added do not add http:// because most users who enter the data always enter the URLs without it. So when displaying it in the single attachment file, we simply added http:// before adding this tag. However, you are right that adding the esc_url would make it much easier. Thanks. Updated the post.

    • wpbeginner says:

      Just remembered that another reason was that we wanted to display the URL itself without the http:// as text.

  20. Bill Erickson says:

    For the URL field, instead of telling the user not to include the http://, change your be_attachment_field_credit_save() function to this:

    if( isset( $attachment[‘be-photographer-url’] ) )

    update_post_meta( $post[‘ID’], ‘be_photographer_url’, esc_url( $attachment[‘be-photographer-url’] ) );

    esc_url will ensure it is a properly formatted URL.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.