WordPress.org

Ready to get started?Download WordPress

Forums

[Theme: Codium] editing functions.php for header height : fatal error (3 posts)

  1. Sam
    Member
    Posted 2 years ago #

    I understand that, in order to change the header height, I need to change 2 area of the functions.php.

    // This theme allows users to set a custom header image
    	define('HEADER_TEXTCOLOR', '444');
    	define('HEADER_IMAGE_WIDTH', 980); // use width and height appropriate for your theme
    	define('HEADER_IMAGE_HEIGHT', 250);
    
    // gets included in the site header
    function codium_extend_header_style() {
        if (get_header_image() != ''){
        ?><style type="text/css">
            div#header {
                background: url(<?php header_image(); ?>); height :230px; -moz-border-radius-topleft:6px;border-top-left-radius:6px;-moz-border-radius-topright:6px;border-top-right-radius:6px;
            }
            <?php if ( 'blank' == get_header_textcolor() ) { ?>
    		h1.blogtitle,.description { display: none; }
    		<?php } else { ?>
    		h1.blogtitle a,.description { color:#<?php header_textcolor() ?>; }
        	<?php
    		} ?>
    		</style><?php
    		}
    	}

    When I try to upload the new functions.php to my child theme folder on teh server, however, I get a fatal error:

    Fatal error: Cannot redeclare codium_extend_header_style() (previously declared in /home/content/42/8667842/html/wp-content/themes/everyday/functions.php:10) in /home/content/42/8667842/html/wp-content/themes/codium-extend/functions.php on line 33

    I have created a separete functions.php with only this:
    <?php

    // This theme allows users to set a custom header image
    	define('HEADER_TEXTCOLOR', '444');
    	define('HEADER_IMAGE_WIDTH', 980); // use width and height appropriate for your theme
    	define('HEADER_IMAGE_HEIGHT', 220);
    
    // gets included in the site header
    function codium_extend_header_style() {
        if (get_header_image() != ''){
        ?><style type="text/css">
            div#header {
                background: url(<?php header_image(); ?>); height :215px; -moz-border-radius-topleft:6px;border-top-left-radius:6px;-moz-border-radius-topright:6px;border-top-right-radius:6px;
            }
            <?php if ( 'blank' == get_header_textcolor() ) { ?>
    		h1.blogtitle,.description { display: none; }
    		<?php } else { ?>
    		h1.blogtitle a,.description { color:#<?php header_textcolor() ?>; }
        	<?php
    		} ?>
    		</style><?php
    		}
    	}
    ?>

    What am I doing wrong??
    Thanks.

  2. Sam
    Member
    Posted 2 years ago #

    I can, of course, upload the edited functions.php directly to the themes/codium-extend, but I want to make sure it is in my child theme if there is a theme update.

  3. TechDistortion
    Member
    Posted 2 years ago #

    It may be a little late but I found myself in the same situation you were in just two days ago. After a lot of searching and learning how WordPress have implemented their PHP/CSS I came to the following solution.

    Before I go on I need to say that this is likely not the only solution nor is it necessarily the best solution I know only that it works well for me on my site: techdistortion.com

    The way codium-extend creates its custom header is by using the function add_custom_image_header() and it references two functions to do so: codium_extend_header_style() and codium_extend_admin_header_style(). These are all located in the functions.php file in the parent theme (codium-extend). Since you can't redefine previously defined variables and since you can't over-ride already defined functions neatly, it's just easier to ignore those two functions created by codium-extend and simply create your own. He's what I did:

    <?php
    // gets included in the site header
    function td_header_style() {
        ?><style type="text/css">
        div#header {
        background: url("http://techdistortion.com/wp-content/themes/codium-extend-td/TD-1090x120.png") no-repeat;
        height :120px;
        -moz-border-radius:6px;
        border-radius:6px;
    }
    <?php if ( 'blank' == get_header_textcolor() ) { ?>
        h1.blogtitle,.description { display: none; }
        <?php } else { ?>
        h1.blogtitle a,.description { color:#<?php header_textcolor() ?>; }
        <?php
        } ?>
        </style><?php
    }
    
        // gets included in the admin header
    function td_admin_header_style() {
        ?><style type="text/css">
        #headimg {
        width:1090px;
        height:120px;
        }
        </style><?php
    }
    ?>

    After this we've now setup the two functions how we want them and it's time to remove the existing image header for which WordPress provide a function appropriately called remove_custom_image_header(). In order to execute this and our two new functions we need to wrap them in an action that takes place after the theme has finished its setup (if we don't we'll be removing an image header that hadn't been created yet = this is bad) as follows:

    <?php
        add_action( 'after_setup_theme','remove_image_header', 100 );
        function remove_image_header() {
            remove_custom_image_header();
            add_custom_image_header('td_header_style', 'td_admin_header_style');
        }
    ?>

    Of course you can name your two new functions whatever you like but I prefixed mine with "td" after my site.

    All of this is all well and sedentary but the problem is that as of WordPress v3.4 (not released yet but will be soon) the add_customer_image_header is going to be deprecated. It's advisable then to look into add_theme_support ('custom header'); after that point. I'm assuming there will be an update to codium-extend to support add_theme_support at that time.

Topic Closed

This topic has been closed to new replies.

About this Topic