add images sizes to the media insert box

Community Forums Forums General Discussion add images sizes to the media insert box

This topic is: not resolved

This topic contains 4 replies, has 4 voices, and was last updated by  BossLady 11 months, 1 week ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #11294

    preynolds
    Participant
    Post count: 1

    Hi,

    I’d like to add a custom image size for the end user to select when inserting an image into a post or page. I see the custom image sizes in the functions.php file and have added a new one there: add_image_size(‘FrontPageImage’, 470, 290, TRUE);

    However, these custom sizes don’t show up in the options box when inserting an image into a post or page. I’ve found instructions from outside studiopress on how to do that, but they have the add_image_size inside a function and genesis does not, so I don’t want mess up the syntax.  http://pippinsplugins.com/add-custom-image-sizes-to-media-uploader/

    I’m using the Metric child theme at http://www.mse.berkeley.edu/

    Can I get some help on making my custom image size appear in the image insert box?

    thanks, Pam

    #13430

    David Decker
    Moderator
    Post count: 93

    Hi there!
    There is no other way of doing it as you’ve already found on this tutorial: http://pippinsplugins.com/add-custom-image-sizes-to-media-uploader/ :-)

    I am also using this approach on my site and it’s working great! I just did make you a code snippet which you can use for Genesis child themes. Please note: make a backup of your functions.php file before (always best practice, hehe!). Then add this piece of code into the functions.php file of the child, should go at the bottom. Please DON’T add the beginning line where it says “< ? php" ok?

    the 2 lines will add 2 new entries to the drop-down field in the uploader. Just add as many lines to this function as you need. Where the ID in the $sizes variable always is the ID of the added image size, so this has to be the same as in add_image_size: add_image_size( 'mini120', 120, 120, TRUE ); —> then the ID is “mini120″. Ok? :)

    For the Label just add a name so you could recognize it later when uploading — for me this is very important or for clients so they know easily what it means.

    I hope that helps, Dave :)


    #40364

    BossLady
    Participant
    Post count: 27

    Hi Dave,
    So glad I found this post! I’m struggling a little and need some guidance, though. I inserted your code and in the media uploader I can see the name I gave my image size but no image size in parentheses and I’m not able to click on it. I get a little confused about what I’m supposed to replace and I think that’s my issue here. The “ddw” is throwing me a little because I know that child theme names get used in the php functions, but I’m not sure that is the case here. Also, where it says “your-textdomain” I’m not sure what to put there, either. I’m using Optimal theme, so I put optimal in there but it isn’t working, so I’m thinking clearly that’s not it.

    Here’s what I added to the bottom, if it helps:
    `add_filter( ‘image_size_names_choose’, ‘ddw_show_custom_image_sizes_in_uploader’ );
    /**
    * Show custom image sizes in media uploader.
    *
    * @author David Decker – DECKERWEB
    * @link http://deckerweb.de/twitter
    */
    function ddw_show_custom_image_sizes_in_uploader( $sizes ) {

    $sizes['home-slider'] = __( ‘Home Slider’, ‘optimal’ );

    return $sizes;
    }
    `

    And for the image I just added
    `add_image_size( ‘home-slider’, 600, 350, TRUE );`
    underneath the other ones Wes (Appfinite) added.

    Thanks so much for any help/course correction – truly appreciated!!

    #40392

    essaysnark
    Participant
    Post count: 266

    Hey BossLady – I think you’re almost there! I’m pretty sure Dave is based in Germany and so he’s well into his weekend already so I thought I’d try my hand at this.

    First of all, the “ddw” prefix to the function name is simply Dave’s initials – Dave Decker Web – that’s to make sure that the function name is unique among your WP installation when you paste it in.

    The tricky part with Dave’s code is the “textdomain” thing which is something he probably does all the time since he’s frequently translating WP stuff to German. This should not be your theme name, and in fact you probably don’t need it at all since you’re working just in English right? I’m not exactly sure what the correct value would be to put there since I don’t know anything about that translation stuff. I think you could just change that one line in your function to this:

    	$sizes['home-slider']                    = __( 'Home Slider' );
    

    but I’m honestly not sure. If that doesn’t work and you’re in a hurry, you could try a variation of the same function that I found here: http://wp.tutsplus.com/tutorials/theme-development/using-custom-image-sizes-in-your-theme-and-resizing-existing-images-to-the-new-sizes/ It does the same thing in a slightly different way. Or, I’m sure that Dave will pop in here when he can. But I wanted to try my hand at it (learning opportunity!).

    #40394

    BossLady
    Participant
    Post count: 27

    Oh EssaySnark – thanks so much!!! I just deleted ‘optimal’ and that was all it took! Wahoo! If this was a learning opportunity for you, it was a very wisely chosen one.

    Many thanks,
    BossLady :)

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.