Changing header image in WordPress twentyseventeen theme with a plugin
I’m setting up a blog network using WordPress multi-user / multi-site a.k.a. WordPress network. Each new blog should be looking good from the start and the current header image is a real blotch.
There are a number of approaches to solve this:
Create a child theme
Make changes in the current theme, by editing the code in the relevant files / Replace the bad-looking standard picture in the folder.
Create a plugin
Edit the functions.php file
I had a good time suffering. Mentally. I knew instantly that a plugin would be best for me. But how to make it happen?
The solution that works for plugin, child theme and functions.php is to work with a filter in twenty seventeen.
In inc/custom_header.php the following function is written, to apply custom-header:
add_theme_support( 'custom-header', apply_filters('twentyseventeen_custom_header_args', array(
'default-image' => get_parent_theme_file_uri( '/assets/images/header.jpg' ), 'width' => 2000, 'height' => 1200, 'flex-height' => true, 'video' => true, 'wp-head-callback' => 'twentyseventeen_header_style', ) ) );
The interesting part with this is the apply_filters(’twentyseventeen_custom_header_args’, ...). It means there is a filter added for the header arguments. Let’s use that!
function my_function_that_changes_header_options ($args) { $args ['default-image'] = ''; // Sets the default-image to nothing. return $settings; }
add_filter('twentyseventeen_custom_header_args','my_function_that_changes_header_options');
Before figuring out above, I was struggling with unregister_default_headers and register_default_headers. What these functions do are to add or remove what is seen in the admin interface. You can unregister the header.jpg image, so that it won’t be visible in the customization area, but it won’t change the header.jpg. Likewise, you can add an additional image in the customization area, but it won’t change the header.jpg.












