'Conditional header in wordpress
I'm trying to have two different headers display for the homepage and for anything else.
I set in wordpress settings > reading : the homepage as a "static page" a page I pubblished named "Homepage".
My code should display the <div class="home_header"></divin the homepage and <div class="page_header"></div> in all other pages or posts.
The code doesn't seem to work and displays <div class="page_header"></div> to all pages, Homepage included.
my code is
<header id="masthead" class="site-header">
<div class="site-branding">
<?php
if ( is_front_page() && is_home() ) :
?>
<div class="home_topbar">
<div class="contatti_sx">
<address>Via Indirizzo, 2, 00000 Paese RE</address><a href="tel:+393335554444">+39 333 555 4444</a>
</div>
<div class="socials">
<a href="https://www.facebook.com"><i></i></a>
<a href="https://www.instagram.com"><i></i></a>
</div>
<div class="language">
<a href="">IT</a><a href="">EN</a>
</div>
</div>
<div class="copertina">
<h4>EMILIA - La Bassa</h4>
<h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
<img src="<?php the_post_thumbnail() ?>" alt="">
</div>
<div class="menu_bar">
<div class="logo"><?php the_custom_logo(); ?></div>
<nav id="site-navigation" class="main-navigation">
<button class="menu-toggle" aria-controls="primary-menu" aria-expanded="false"><?php esc_html_e( 'Primary Menu', 'cdnonni' ); ?></button>
<?php
wp_nav_menu(
array(
'theme_location' => 'menu-1',
'menu_id' => 'primary-menu',
)
);
?>
</nav><!-- #site-navigation -->
<div><a href="prenotazioni" class="prenotazioni"></a></div>
</div>
<?php
else :
?>
<div class="page_topbar">
<div class="contatti_sx">
<address>Via Indirizzo, 2, 00000 Paese RE</address><a href="tel:+393335554444">+39 333 555 4444</a>
</div>
<h1 class="topbar_title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
<div class="socials">
<a href="https://www.facebook.com"><i></i></a>
<a href="https://www.instagram.com"><i></i></a>
</div>
<div class="language">
<a href="">IT</a><a href="">EN</a>
</div>
</div>
<div class="menu_bar">
<div class="logo"><?php the_custom_logo(); ?></div>
<nav id="site-navigation" class="main-navigation">
<button class="menu-toggle" aria-controls="primary-menu" aria-expanded="false"><?php esc_html_e( 'Primary Menu', 'cdnonni' ); ?></button>
<?php
wp_nav_menu(
array(
'theme_location' => 'menu-1',
'menu_id' => 'primary-menu',
)
);
?>
</nav><!-- #site-navigation -->
<div><a href="prenotazioni" class="prenotazioni"></a></div>
</div>
<?php
endif;
?>
</div><!-- .site-branding -->
</header><!-- #masthead -->
which can be summarized to
<header id="masthead" class="site-header">
<div class="site-branding">
<?php
if ( is_front_page() && is_home() ) :
?>
<div class="home_header">
</div>
<?php
else :
?>
<div class="page_header">
</div>
<?php
endif;
?>
</div><!-- .site-branding -->
</header><!-- #masthead -->
where did I make a mistake? Thank you!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
