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

    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.

  • James Murray

    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

      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!

  • Linus

    Hello!

    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?

  • Patrik Illy

    Hi,
    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

  • Baylock

    Hi,

    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!

    • http://www.wpbeginner.com Editorial Staff

      Modify the priority numbers from 10 to 5.

      • Baylock

        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'];
        unset($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.

  • Donna Fontenot

    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! :)

  • Sacha

    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?

  • smattiza

    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.

    • http://www.wpbeginner.com/ wpbeginner

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

  • http://www.wpbeginner.com Editorial Staff

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

  • EB

    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

    • http://www.wpbeginner.com/ wpbeginner

      That line has nothing to do with it. It seems that the error is happening before that.

  • markus

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

  • http://www.wpbeginner.com/ wpbeginner

    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.

    • http://www.wpbeginner.com/ wpbeginner

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

  • http://www.billerickson.net/ Bill Erickson

    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.