I'm pretty new to WordPress, so please forgive any ignorances.

I have a child theme which I've implemented, which works okay, but I need to display a banner in the header section, where there is no widget area. The idea is that I use a custom field to identify some aspect of the page, and then display a banner according to that value.

So, I found that I could copy header-main.php into /my-child-theme/parts/, and add some additional code which identifies the field value and then queries a non-WP database. This works okay too. No problems.

However, I realize that when the main theme gets updated my header-main.php file (in the child theme) will not get updated, which could later cause issues.

So, I'm wondering if there is a better way or, rather, a correct way of achieving what I'm attempting to do, taking account of the fact that I need the banner to be in a specific place in the header section.

Any suggestions/help appreciated. Thanks!


Not sure I fully understand what you're trying to achieve, but can you make a check on the value of your custom field? Something like this:

if( $field == 'banner' ) {
     // Display banner

You can put the code straight into your parent theme's header-main.php and it will only execute if the value of $field is equal to 'banner', like in the case of your child theme.

  • I think the question is quite clear. I certainly wouldn't want to put the code directly into the parent theme's header-main.php; that would be even worse than putting it in the child theme's header-main.php. – Cheddar Nov 22 '17 at 22:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.