WordPress.org

Ready to get started?Download WordPress

Forums

Twenty Ten
[resolved] How to define the header image width and height? (7 posts)

  1. chibib0
    Member
    Posted 2 years ago #

    Hi,

    I'm using the twenty ten theme as my framework on my themes. However, i have themes that needs to have defined width and height of the header image different on the twenty ten default.

    I have defined the height and width on the theme however, the default height and width of twenty ten is still defined on the backend so when cropping the uploaded image, the default height and width is the crop size.

    Is there a solution for this?
    Thank you.

    http://wordpress.org/extend/themes/twentyten/

  2. esmi
    Forum Moderator
    Posted 2 years ago #

    Do not edit the Twenty Eleven theme. It is the default WordPress 3.2 theme and having access to an unedited version of the theme is vital when dealing with a range of site issues.

    Create a child theme for your customisations. Once your child theme is active, see this article.

  3. peredur
    Member
    Posted 2 years ago #

    The image is inserted using the following code in header.php:

    // Check if this is a post or page, if it has a thumbnail, and if it's a big one
    if ( is_singular() && current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $post->ID ) && ( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) && $image[1] >= HEADER_IMAGE_WIDTH ) :
      // Houston, we have a new header image!
      echo get_the_post_thumbnail( $post->ID );
    elseif ( get_header_image() ) : ?>
      <img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />
    <?php endif; ?>

    You best bet is probably is probably either to redefine the constants HEADER_IMAGE_WIDTH and HEADER_IMAGE_HEIGHT or to just hard code in the image you want.

    As it's the twentyten theme, you really *must* do this in a child theme.

    HTH

    PAE

  4. chibib0
    Member
    Posted 2 years ago #

    @peredur

    When i redefine the constants HEADER_IMAGE_WIDTH and HEADER_IMAGE_HEIGHT by creating a functions.php inside the child theme there is a "Cannot Redeclare Error".

  5. esmi
    Forum Moderator
    Posted 2 years ago #

  6. peredur
    Member
    Posted 2 years ago #

    First off, of course, esmi is correct.

    As for the constants, I'm sorry, I misled you. You can't redefine a constant. You need to make sure that the function in which the constants are defined is overwritable. I.e. it should be surrounded by:

    if(!function_exists('function_name')) {
        ...
    }

    That being the case, you can create another function of the same name in your child theme by copying the old one into your functions.php file and changing the bits you need to change.

    In twentyten the function is called twentyten_setup(). I'm not sure about twentyeleven, but it should be similar.

    Sorry about the confusion

    Cheers

    PAE

  7. chibib0
    Member
    Posted 2 years ago #

    Thank you guys! It works! ^_^v

Topic Closed

This topic has been closed to new replies.

About this Theme

About this Topic

Tags