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

Comments

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

  2. 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!

  3. Linus says:

    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?

  4. Patrik Illy says:

    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

  5. Baylock says:

    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!

    • 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'];
        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.

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

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

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

  9. Editorial Staff says:

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

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

  11. markus says:

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

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

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