Why can you not put the hero logic / class in header.php with the nav?
If the navbar is wrapped in the same div wrapper as the hero, and each page has a different hero that is set by the class of the hero div wrapper, then all pages will have the same hero because the hero wrapper class will be hard coded in header.php
https://stackoverflow.com/questions/66214975/transparent-nav-in-header-php
So if the page template can work out the hero class, then so can the header template.
in header.php something like
if (is_singular()) {
$post = get_post();
$hero_class = some logic to get the class
You could also insert the code by firing wp_head hook of creating your own acton or filter hooks in the header
I’m gonna have to read up a bit more about this. This is the first site I’ve ever built. Thanks for your help.
So how are you pull out the appropriate class – it that stored in post meta or somewhere?
I first built the site as a static site using just html, js and css, so each page has its own independent html where I’ve just added the appropiate wrapper classes.
I’ve been learning wordpress the past couple of days as I’ve tried to convert the site into a wordpress theme. So my wordpress knowledge is limited at the moment.
Thanks. I’ve managed to get everything working properly apart from my issue with the transparent navbar. I’ve enqueued all my css and js files, enabled various theme options in function.php, created navigation locations, also I’ve got the blog archive.php and single.php working properly with my blog.
I just need to work out now how to identify which page template is being used and add the class dynamically to my html in header.php I think.
if (is_singular()) {
$post = get_post();
$template = get_post_meta( $post->ID, '_wp_page_template', true );
switch ( $template ) {
case 'myone-page.php':
$class = 'myone';
break;
case 'mytwo-page.php':
$class = 'mytwo';
break;
default:
$class='';
}
Legend! Thanks very much for your help
or
if (is_singular()) {
$template = get_page_template_slug();
switch ( $template ) {
case 'myone-page.php':
$class = 'myone';
break;
case 'mytwo-page.php':
$class = 'mytwo';
break;
default:
$class='';
}