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.

How was it for you? Let me know on BlueSky or Mastodon

(Please) Link to this page

Thanks for reading. I'd really appreciate it if you'd link to this page if you mention it in your newsletter or on your blog.

Related Posts

18 Jan 2013

Mimbo Pro 4

I recently created a promotional video for Mimbo Pro 4 – showcasing the newest functionality from the theme.I’ve been really pleased with how Mimbo Pro has done on WordPress.com and a lot of the new functionality and developments have developed...
12 Mar 2008

Pro Theme Design and Mimbo Pro

The last couple of months I have been spending my free time working on a new website and premium theme.The website is called Pro Theme Design, and the theme is Mimbo Pro.Pro Theme DesignPro Theme Design is a WordPress theme...
13 May 2010

6 Tips to Build Better WordPress Themes

If you want to make WordPress themes, for clients, to release for free or to sell, then there are a lot of factors you need to take into consideration. Below are some hints and tips that should help ease your...
02 Feb 2012

WordPress Theme Framework: Less Is More – Or Is It?

I have a conundrum. I want to improve Elemental – my WordPress theme framework. I want to make it lean and fast; but this will involve removing functionality. This in turn means that when people upgrade their themes things may...
15 Jan 2010

Building WPVote Part 5 : Programming

I’m nearly finished with the design of my new WordPress voting site, WPVote, so now need to look more closely at the programming.I enjoy dissecting WordPress themes, and since I also like code simplicity and minimalism (and am working with...
08 Aug 2013

The Death of WordPress Theme Frameworks

WordPress theme frameworks are on their way out. They’re dying a slow death. At least that’s what I think.Nathan Rice recently wrote an article with his thoughts about theme frameworks – in defense of them – however he clearly has...