Filtering get_header()
Published June 15th, 2012 under General
Just a quick code snippet here for anyone attempting to filter get_header() in WordPress. This is a useful feature for developers wanting to modify the header image of a site without needing to mess with the theme.
There is no direct filter in get_header(), but it turns out this is not necessary as you can filter ‘theme_mod_header_image’, which is found inside the get_theme_mod() function in wp-includes/themes.php.
The following snippet will programatically replace the header with another photo.
<?php
/*
* Filter for modifying the output of get_header()
*
* @author Ryan Hellyer <ryan@pixopoint.com>
* @since 0.1
*/
function some_header_image_filter( $url ) {
return 'http://ryanhellyer.net/files/2012/04/oslo-city1-680x313.jpg';
}
add_filter( 'theme_mod_header_image', 'some_header_image_filter' );
Thanks to Mark Heijnen for tracking down the filter
I was originally trying to use get_theme_mods() which was of no use at all.