Customising WordPress Custom Headers in Child Themes

I am currently working on the next version of Mimbo Pro (due for release really really soon), and am updating the child themes to work with the new update.

Part of the update is that we (Darren and I) wanted to make the best use of the built in WordPress functionality. One of the elements we wanted to take care of was making sure the header is as flexible as possible. Adding the custom WordPress headers is easy. There's documentation on it on the Codex. Just add a few defines, a couple of callback functions, and you're set.

define( 'HEADER_TEXTCOLOR', 'ffffff' );
define( 'HEADER_IMAGE', '%s/images/bg_masthead.jpg' );
define( 'HEADER_IMAGE_WIDTH', 960 );
define( 'HEADER_IMAGE_HEIGHT', 108 );

The problem is when you want to override these default settings in child themes. You can't just define them again in the child themes functions.php because this will throw up PHP errors.

The solution was actually really simple but it took a bit of thinking to realise all I needed to do is wrap the default properties in a filter so that they could be accessed through the child theme.

define( 'HEADER_TEXTCOLOR', apply_filters( 'mimbo_header_textcolor', 'ffffff' ) );
define( 'HEADER_IMAGE', apply_filters( 'mimbo_header_image', '%s/images/bg_masthead.jpg' ) );
define( 'HEADER_IMAGE_WIDTH', 960 );
define( 'HEADER_IMAGE_HEIGHT', 108 );

Then in the child themes functions.php all I have to do is:

function dispatch_header_textcolor() {
	return '000000';
}

function dispatch_header_image() {
	return '%s/images/logo.gif';
}

add_filter( 'mimbo_header_textcolor', 'dispatch_header_textcolor' );
add_filter( 'mimbo_header_image', 'dispatch_header_image' );

Ok - not very exciting, but I found it very helpful so I'm making a note in case I need it in the future.

Share This...

About The Author

Ben Gillbanks

Web Designer, Video Gamer, Blogger, and part time Entrepreneur. Read More

2 thoughts on “Customising WordPress Custom Headers in Child Themes

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

My Projects

TimThumb - Image Resize Script TimThumb

Image Resize Thumbnail Script

WPVote - WordPress Social Voting WPVote.com

WordPress Social Voting Site

About me

About BenMy name is Ben Gillbanks. I'm a lover of Video Games, WordPress, Web Development and everything in between.

I have been working on the internet since 1998, and working with computers even longer. I am a hardcore Nintendo fanboy and have owned most of their consoles at one stage or another.

Read more about me on my about page.

Binary Moon

WordPress and Web Development › home of Ben Gillbanks