2

I am trying to change the height of my featured image to 350px in my child theme for Twenty Eleven.

Can anyone help??

Note: I am using Twenty Eleven and there is no functions.php file in my child theme, because the parent theme's functions.php file is included after the child theme's functions.php file.

When creating a child theme, you do not copy the functions.php file from the parent theme.

The only files I have in the child theme are style.css, header.css and footer.css.

I haven't added any code yet for the change in height for the featured image because I don't know what to put - would love some help.

1
  • I am using Twenty Eleven and there is no functions.php file in my child theme, because the parent theme's functions.php file is included after the child theme's functions.php file. When creating a child theme, you do not copy the functions.php file from the parent theme. The only files I have in the child theme are style.css, header.css and footer.css. I haven't added any code yet for the change in height for the featured image because I don't know what to put.
    – wolf
    Jul 12, 2012 at 11:49

3 Answers 3

2

If you want another size of the feature images in the Child theme than the parent theme you should add a functions.php file to the child theme and add specific functions for that theme.

From WordPress Codex about child theme functions.php

Unlike style.css, the functions.php of a child theme does not override its counterpart from the parent. Instead, it is loaded in addition to the parent’s functions.php. (Specifically, it is loaded right before the parent’s file.)

So lets say you want the child themes feature image size to be 150x150px you just add add_image_size to the childs functions.php file.

An example when the parent already have support for post-thumbnails you just add the thumbnail size:

if ( function_exists( 'add_theme_support' ) ) {
    add_theme_support( 'post-thumbnails' );
    set_post_thumbnail_size( 150, 150 ); // default Post Thumbnail dimensions
}

If you want more sizes only on the child theme you just add:

if ( function_exists( 'add_image_size' ) ) { 
    add_image_size( 'category-thumb', 300, 9999 ); //300 pixels wide (and unlimited height)
    add_image_size( 'homepage-thumb', 220, 180, true ); //(cropped)
}

And then call it by:

<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'category-thumb' ); } ?>
1

you must create a child theme with a functions.php file and in the file include the following

function mytheme_setup() {
    set_post_thumbnail_size(624, 260, true);
}
add_action('after_setup_theme', 'mytheme_setup', 20);

the last argument to the add_action call is the priority. Since this call will be made before the call from the parent theme you must make sure that the priority is higher than that of the parent theme so that the setup function of the child is run after that of the parent (if they have the same priority they will be run in registration order). Twentytwelve use the default priority, which is 10.

0

If I understand your situation right, this is what you need to do.

Your parent theme being Twenty Eleven uses this function to create a custom image size:

add_image_size( 'small-feature', 500, 300 );

You can filter the twentyeleven_setup() function to change the image size—but that's outside the scope of my coding knowledge. So, instead, we can create our own image size and use it.

  1. Create an empty functions.php file with the following code and drop it in your child theme directory (notice that the new function below has 350 and not 300—which is what you wanted):

    <?php
        add_image_size( 'custom-small-feature', 500, 350 );
    
  2. Now, copy the showcase.php file in your parent theme to your child theme's directory. In it, replace this:

    $thumbnail_size = 'small-feature';
    

    with this:

    $thumbnail_size = 'custom-small-feature';
    

That should do it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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