• Resolved stevedw

    (@stevedw)


    Ive created a TwentyTen Child Theme. I want to change the URL of the header image and also change the height and width of the image.

    What do i have to put in functions.php to change these settings so it overrides the settings in the default TwentyTen theme?

    Below is the functions.php which ive copied to the twentyten-child folder. It’s not working correctly. It just displays the text at the top of the site above the header.

    function twentyten_setup() {
    // Your changeable header business starts here
    define( 'HEADER_TEXTCOLOR', '' );
    // No CSS, just IMG call. The %s is a placeholder for the theme template directory URI.
    define( 'HEADER_IMAGE', '%s/images/header.png' );
    
    // The height and width of your custom header. You can hook into the theme's own filters to change these values.
    // Add a filter to twentyten_header_image_width and twentyten_header_image_height to change these values.
    define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyten_header_image_width', 940 ) );
    define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyten_header_image_height', 198 ) );
    }
    endif;
Viewing 15 replies - 1 through 15 (of 15 total)
  • To change the header width/height (and bear in mind that this is off the top of my head), try:

    function my_header_width($width) {
    	$width = xx; // width in pixels;
    	return $width;
    }
    function my_header_height($height) {
    	$height = xx; // height in pixels;
    	return $height;
    }
    add_filter ( 'twentyten_header_image_width', my_header_width );
    add_filter ( 'twentyten_header_image_height', my_header_height );

    in functions.php

    To change the header url, you’re going to have to make a copy of header.php in your child them and amend that template file.

    Thread Starter stevedw

    (@stevedw)

    Thanks.

    So do i just need to copy the entire contents of the functions.php file from the main TwentyTen theme to the twentyten-child folder then just modify anything i need to change in the functions.php file such as the image URL and image height and width?

    No. You just have the new or amended functions in the child’s functions.php. You might want to review Child_Themes.

    Thread Starter stevedw

    (@stevedw)

    I entered the code you mentioned in the functions.php in the twentyten-child directory but it just displays the text at the top of the site.

    Here’s the site http://www.gymexerciseathome.com

    What am i doing wrong?

    Make sure that your functions.php file has an opening <?php tag.

    Thread Starter stevedw

    (@stevedw)

    Does it need any closing tags also?

    You can add a closing ?> tag but it’s not absolutely necessary and it’s often better if you don’t use it.

    Thread Starter stevedw

    (@stevedw)

    You said i need to make a copy of header.php to change the header URL.

    Ive just looked at the header.php file but i don’t see the header URL anywhere. Is this the correct file to use?

    Or should i put the code in functions.php instead to change the header URL?

    header.php is the correct file and the relevant line is <a href="<?php echo home_url( '/' ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a>

    Thread Starter stevedw

    (@stevedw)

    I see there’s also a URL to change the header image in functions.php
    Is that just an alternative way of changing the header image?

    Does the header image URL which is set in header.php override what is says in functions.php

    Ive copied the entire functions.php file to the twentyten-child folder then edited the code but it hasn’t changed the header image. It just has the default path.jpg header. Here’s the section of the code which i put for the URL.

    <<?php echo $heading_tag; ?> id="site-title">
    					<span>
    						<a href="<?php echo home_url( 'twentyten-child/images/header.png' ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a>
    					</span>
    				</<?php echo $heading_tag; ?>>
    				<div id="site-description"><?php bloginfo( 'description' ); ?></div>

    What does it seem the problem is?

    There’s no header url in functions.php – only the url of the header image.

    Ive copied the entire functions.php file to the twentyten-child folder

    Don’t copy the whole file over! You have to create a new functions.php file in your child theme.

    Thread Starter stevedw

    (@stevedw)

    Ive followed the instructions on this site – http://wpti.ps/functions/replace-default-header-image-twenty-ten-theme/ and created a new functions.php in the twentyten-child directory and copied lines 75-178 of the Twenty Ten functions.php into it like it explains to do.

    Problem is, when i edited the section below of functions.php to change the header image URL it doesn’t display the new header image.

    define( 'HEADER_IMAGE', '%s/images/header.png' );

    As you can see it just shows a red X on the site – http://gymexerciseathome.com/

    The actual header image i want it to display is located at twentyten-child/images/header.png How do i get it to display this header image?

    Thread Starter stevedw

    (@stevedw)

    It’s working now. The problem was i missed out the part in the code get_bloginfo('stylesheet_directory')

    The problem im having now is the black bar is to low down by around 32 pixels. My header image is 940×90 but the black bar is around 120 pixels low down.

    How do i move the black bar up by around 32 pixels so the header image is shown at it’s correct height size?

    Here’s the code im using for the style.css file for the Child Theme.

    [CSS moderated as per the Forum Rules. Please just post a link to your site.]

    Also in the Child Theme’s functions.php ive set the code to;

    define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyten_header_image_width', 940 ) );
    	define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyten_header_image_height', 90 ) );

    Please refer to my earlier answer & code example.

    Thread Starter stevedw

    (@stevedw)

    Ive done it now although i didn’t use a copy of header.php to change the header image. I just copied lines 75-178 from the functions.php file when i created a new functions.php for the child theme.

    Thanks,

Viewing 15 replies - 1 through 15 (of 15 total)

The topic ‘TwentyTen Child Theme – Functions.php’ is closed to new replies.