I'm wondering if it is possible to use different image sizes (medium, large) for the content on the homepage and single post pages. I have a narrow column on the homepage than on the single post pages and different image sizes would be nice.



If your talking about the images that are written into $post->post_content (the_content()) you'll either need to write a filter that strips out all images and replaces them with the smaller version. Or you could just use CSS. For CSS make sure you have body_class() in your body tag then you can localise a maxwidth to your home page.

body.home .post img{
  • Note that .home applies to the Site Front Page, and not necessarily the Blog Posts Index (which uses .blog). – Chip Bennett Dec 8 '11 at 20:33

If you're using the body_class() template tag, you can modify content-image max-width using CSS. For example:

#content img {
    max-width: 600px;
    height: auto;
.blog #content img,
.archive #content img {
    max-width: 450px;

See the Template Hierarchy and body_class() Codex entries for more CSS class information.

# functions.php - hook on 'after_setup_theme'
// Posts & Pages - if only posts, go with is_single()
if ( is_singular () )
    add_image_size( 'sidebar', 150, 150, true );
    add_image_size( 'sidebar', 200, 200, true );

// inside your post template
echo get_image_tag( $id, $alt, $title, $align, 'sidebar' );

If you are using featured images you could use the following inside your loop.

if( has_post_thumbnail() ) {

Where medium is the image size you want to fetch.

If you are using the attached images you could use the following functions.

wp_get_attachment_image($attachment_id, 'medium');
wp_get_attachment_image_src($attachment_id, 'medium');

The first one gives you the img tag while the second one gives you an array containing image source, width and height. You can use this function if you know the id of the attachment.

To create extra image sizes when you upload an image you can use the add_image_size( 'custom', 210, 210, true ); function and then call the size custom instead of the other sizes ( thumbnail, medium, large, full ). This function automatically creates an extra image with the dimensions specified ( if the dimension of the image are bigger than the specified dimensions ) when you upload an image through the media library. Now since you have already uploaded your images you would need to use the regenerate thumbanils plugin to generate the newly added image sizes.

  • I know that. I'm not talking about the post thumbnail, but about the images which are in my posts – fabianpimminger Dec 8 '11 at 18:40
  • I have updated the answer... Let me know if that helps... – Joshua Abenazer Dec 8 '11 at 18:49
  • yeah. I'm reffering to the images already included in my posts. Is there any filter-method to change the size of these images. – fabianpimminger Dec 9 '11 at 15:39
  • you could use add_image_size() then. Check the updated answer. – Joshua Abenazer Dec 9 '11 at 15:51

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.