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.

Was it good/ useful/ a load of old rubbish? Let me know on Mastodon, or BlueSky (or Twitter X if you must).

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.

WordPress News

The latest WordPress updates from the WPBriefs Podcast.

Related Posts

20 Jul 2016

Empathy in Web Design

I wasn’t able to make WordCamp Europe this year, but they’ve been really quick at getting all of the talks online, and so I have been watching some of them – and this one stood out.Morten Rand-Hendriksen is an experienced...
27 May 2013

WordPress: 10 Years Young, What Does The Future Hold?

WordPress is now 10 years old. I started using wordpress 9 years ago – which means I joined the WordPress community early on. The reason I chose WordPress is simply because of the fabled 5 minute install process – I...
31 May 2007

WordPress tips and tricks – functions.php

Functions.php is a little known wordpress template file. Not many themes take advantage of it but , used properly, it can be incredibly powerful. The file can be used as a way to add your own functions to wordpress themes...
19 Jun 2008

Redesigning the WordPress admin Redesign

Ever since the first betas of WordPress 2.5 I have been making my own version of the admin panel. I like a lot of what they have done but there were some very basic things missing in the design, and...
21 Mar 2014

How to Get Started With WordPress Theme Development

I was asked recently how to get into WordPress themeing and so I thought I would answer publicly. Perhaps my thoughts can help others.When I first started using WordPress things were much simpler. The default theme was an index.php and...