1

I am new to wordpress and i want to use a size which can be 300 x 283, i tried the the_post_thumbnail(array('300,283')) but it didn't work, then i went to read about add_image_size which i added like so add_image_size( 'homepage-thumb', 220, 180, true );, gave my post_thumbnail same dimension but nothing happened, am i missing something? how to u my newly added add_image_size in the_post_thumbnail

2

By default Wordpress has three four different image sizes: full, large, medium, thumbnail. If you don't need more than three images size, you can set the with and height of the default image sizes. For example:

add_action( 'after_setup_theme', 'theme_setup' );
function theme_setup() {
    // Be sure your theme supports post-thumbnails
     add_theme_support( 'post-thumbnails' );
    //set thumbnail size to 150 x 150 pixels
    set_post_thumbnail_size( 150, 150);
    //For the other images size it must be used update_option() function.
    //For example, set width to 300 px and height to 200 px for medium size (this is a native image size in Wordpress).
    if (get_option('medium_size_w') != 300 ) {
        update_option('medium_size_w', 300);
        update_option('medium_size_h', 200);
    }
}

Note: the dimensions for each default image size can be configured in the Wordpress admin area. The above code will override this configuration.

If you need more than three image sizes, you want to have your very own image sizes or you don't want to alter the default image sizes, you can add new image sizes using add_image_size() funciton:

add_action( 'after_setup_theme', 'theme_setup' );
function theme_setup() {
   // Be sure your theme supports post-thumbnails
   add_theme_support( 'post-thumbnails' );
   // the params are 'name of the custom size', width (px), height (px) and crop (false/true).
    add_image_size('my-image-size', 300, 110, true);
}

Once the new image size has been added, or the width/height of default sizes have been changed, the upcoming images will have a version with the new image size. The old images must be rebuild. To rebuild the old images you can upload them again or use a plugin, for example AJAX Thumbnail Rebuild. After that, you are ready to use the custom image size anywhere using, for example:

the_post_thumbnail('my-image-size');
|improve this answer|||||
  • if i use add_action( 'after_setup_theme', 'theme_setup' ); function theme_setup() { // the params are 'name of the custom size', width (px), height (px) and crop (false/true). add_image_size('custom-name', 300, 110, true); } will i use the_post_thumbnails('custom-name') – Nofel Sep 23 '13 at 17:07
  • thanks, how can i read more about these. doesn't seem to exist on codex? – Nofel Sep 23 '13 at 17:22
  • The docu exists in codex. Have you seen add_image_size() and the_post_thumbnail()? – cybmeta Sep 23 '13 at 17:27
0

Check out the Codex a little deeper. The answer is there!

the_post_thumbnail( 'your-custom-size' );
|improve this answer|||||
  • if we want to use custom size, why mention name? – Nofel Sep 23 '13 at 16:37
  • the_post_thumbnail() function displays a image, not add a new image size – cybmeta Sep 23 '13 at 16:44
  • I must have misunderstood the question. You asked how to use the new image size (after creating it), right? Just as @cybnet said in the second sample, use add_image_size then when calling for the_post_thumbnail() add in the new image size you created to make the_post_thumbnail('custom-size');. I assumed you had made it through the add_image_size step in the process; next time I'll be a bit more thorough. – ThatDudeLarry Sep 23 '13 at 16:53
  • You are right @ThatDudeLarry, the question was about how to use the new image size but the title of the question was about how to use add_image_size()....confusing. – cybmeta Sep 23 '13 at 17:14
  • @cybnet after creating the function, when i add the_post_thumbnail('my-image-size'); it doesn't have any effect. – Nofel Nov 3 '13 at 17:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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