WordPress.org

Ready to get started?Download WordPress

Forums

Changing header code in functions.php (19 posts)

  1. sbbn
    Member
    Posted 2 years ago #

    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?

  2. Kakoma
    Member
    Posted 2 years ago #

    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?

  3. sbbn
    Member
    Posted 2 years ago #

    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!

  4. Digital Raindrops
    Member
    Posted 2 years ago #

    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.

    http://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

  5. alchymyth
    Forum Moderator
    Posted 2 years ago #

    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.

  6. sbbn
    Member
    Posted 2 years ago #

    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.

  7. sbbn
    Member
    Posted 2 years ago #

    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.

  8. Digital Raindrops
    Member
    Posted 2 years ago #

    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!

    http://pastebin.com/3wVrD58p

    HTH

    David

  9. sbbn
    Member
    Posted 2 years ago #

    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?

  10. Digital Raindrops
    Member
    Posted 2 years ago #

    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

  11. sbbn
    Member
    Posted 2 years ago #

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

  12. Chip Bennett
    Theme Review Admin
    Posted 2 years ago #

    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' );
  13. sbbn
    Member
    Posted 2 years ago #

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

  14. Digital Raindrops
    Member
    Posted 2 years ago #

    Strange, I tested it again!

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

    HTH

    David

  15. sbbn
    Member
    Posted 2 years ago #

    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.

  16. rosie4tune
    Member
    Posted 1 year ago #

    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 :-/

    http://www.travelswithmyhat.com/site

  17. rosie4tune
    Member
    Posted 1 year ago #

    OK so now I realise what I am actually wanting to do is use the featured image, if it exists, as the header image. The COLLECTIONS page has a featured image attached, which is cropped to the theme default 198...

    But the code above is working to upload new header images at the new height. Just need to figure out the feature image part of it now, as I would like certain pages to have their own particular header...

  18. rosie4tune
    Member
    Posted 1 year ago #

    Rightio... so this is all I needed! Just as Chip said :)

    <?php
    
    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' );
  19. fvalmol
    Member
    Posted 1 year ago #

    Sorry.

    I have seen all your comments but I dont know how it works.

    I have copied the code that Chipsaid, and paste in funtions.php

    Is it ok?
    Do I have anythingelse?

    Thank you.

Topic Closed

This topic has been closed to new replies.

About this Topic