• I’m having trouble changing the header image height in functions.php. I created a child theme functions.php file with nothing in it but this:

    define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'brunelleschi_header_image_height', 300) );

    The original code says 198 for the height and I have changed it to 300. The Dashboard now says the image will be 300 px tall, but when I put in an image it gets scaled back down to the original 198 even though I changed the code.

    Are there other lines of code I should be using?

Viewing 15 replies - 1 through 15 (of 18 total)
  • Hi sbbn,
    The name of theme you are using and your site URL would help us give more informed responses BUT have you tried changing CSS instead?

    Thread Starter sbbn

    (@sbbn)

    I forgot the URL, sorry:

    marieprevostonline.com

    I’m using Brunelleschi. I don’t think there’s anything in the style.css to define the header. Here is the code bit for the header in style.css:

    [CSS code moderated – a link to your site is enough to access the styles]

    Thanks!

    Hi, two things,

    The child themes functions.php is run first before the parents functions.php, and you need to remove and reset the filter.

    I hacked this together from one of my a twenty eleven child themes, it is NOT Tested so be careful.

    https://pastebin.com/R8QRS7Bu

    If you change anything update and revise the pastebin for others that might read this topic.

    There is an after setup theme function

    add_action( 'after_setup_theme', 'child_theme_setup' );

    This should:
    Remove and reset the filter.
    Remove the existing header images as they are not tall enough
    Set a new default header from the child themes /images/ folder

    HTH

    David

    but when I put in an image

    did you upload a new image with the new dimensions?

    afaik, the changes will only get applied to new uploaded images.

    Thread Starter sbbn

    (@sbbn)

    Unfortunately that didn’t work, but thanks for trying! I fiddled with the code a bit and kept getting this error:

    Warning: Cannot modify header information – headers already sent by (output started at /home/XXXXXX/public_html/wp-content/themes/brunelleschi-child/functions.php:1) in /home/XXXXXX/public_html/wp-includes/pluggable.php on line 866

    (The X’s are just to block out my administration userid.)

    That line 866 in pluggable.php is:

    header(“Location: $location”, true, $status);

    I’m not really sure what that means.

    Thread Starter sbbn

    (@sbbn)

    Hi alchymyth — Yes, I tried a new image, a custom one that I mocked up just so it would have a 300 px height. It was resized to the original 198 px height.

    Hi,
    I had the wrong arguments for removing the filter (singular), not filters (plural) like I had it in paste one.

    remove_filters( 'brunelleschi_header_image_height');

    Should have been, in paste link two!

    remove_filter( 'brunelleschi_header_image_height', 198);

    This is now Tested Code, I downloaded the theme and created a child theme, and it works fine!

    https://pastebin.com/3wVrD58p

    HTH

    David

    Thread Starter sbbn

    (@sbbn)

    Thank you, but it didn’t work. I am flummoxed. I just cut and pasted it exactly as shown in the pastebin file into a new functions.php in the child theme folder.

    I thought at first the problem was that I had changed the width from 1140 to 1024, but I went back to 1140 and that didn’t work, either.

    I don’t think the problem is anything I did in the style.css file (in my child theme folder). All I changed in there were the colors, and I don’t think I accidentally broke some code while doing so.

    Do you think an uninstall and re-install of Brunelleschi would help?

    Hi,
    Before you do that test the Brunelleschi Child Theme download from this category link, it is the files I used to test the concept.

    HTH

    David

    Thread Starter sbbn

    (@sbbn)

    I downloaded those files, used them (deleting the ones I had in the directory previously) and it still didn’t work.

    You need to add your own filter:

    function brunelleschi_child_filter_header_image_height( $height ) {
        // set equal whatever height you want;
        // e.g. for 300px, use 300
        $new_height = 300;
        // now return it
        return $new_height;
    }
    add_filter( 'brunelleschi_header_image_height', 'brunelleschi_child_filter_header_image_height' );
    Thread Starter sbbn

    (@sbbn)

    My goodness Chip, that did it. Thank you so much! And thank you too, Digital Raindrops!

    Strange, I tested it again!

    Default Headers Removed and New Header Size!
    Screenshot Admin
    Screenshot Website

    HTH

    David

    Thread Starter sbbn

    (@sbbn)

    That is so strange. I assume we both have WP 3.3.2, and we both surely downloaded the same version of Brunelleschi. I have no idea why it didn’t work for me.

    Just wondering Chip if that little snippet is slotted into the functions.php tested by Digital Raindrops, i.e.

    <?php
    /**
     * Tested code by Digital Raindrops modified by Rosie to register new 330 height including Chip's new function at end
    */
    
    add_action( 'after_setup_theme', 'child_theme_setup' );
    
    /** This function will hold any new calls and over-rides */
    if ( !function_exists( 'child_theme_setup' ) ):
    function child_theme_setup() {
    
    	/* Remove Filter and Apply a New Size */
    	remove_filter( 'brunelleschi_header_image_height', 198);
    
    function brunelleschi_child_filter_header_image_height( $height ) {
        // set equal whatever height you want;
        // e.g. for 300px, use 300
        $new_height = 330;
        // now return it
        return $new_height;
    }
    add_filter( 'brunelleschi_header_image_height', 'brunelleschi_child_filter_header_image_height' );}
    endif;

    (that’s my entire functions.php in the child theme folder)

    I can’t seem to get it working :-/

    https://www.travelswithmyhat.com/site

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘Changing header code in functions.php’ is closed to new replies.