Display menu if site is homepage (wordpress)
23,165
Solution 1
You can combine is_front_page()
and is_home()
Wordpress function.
<?php if( is_front_page() && is_home() ) { ?>
// you are on homepage, show your another menu
<?php } else { ?>
<div class="category_menu">
<nav class="cat_menu">
<div class="menu_title parent_cat_name">
<h6><?php echo $category->name; ?></h6>
</div>
<?php rs_left_menu_subcats($subcategories); ?>
</nav>
</div>
<?php } ?>
Solution 2
If you want to display specific content on wordpress homepage than you can do it using is_front_page()
if ( is_front_page() ) {
// your menu code goes here for home page
}
Author by
Pat
Updated on July 05, 2022Comments
-
Pat almost 2 years
On site I have left menu, which appears on almost every subpage
<div class="category_menu"> <nav class="cat_menu"> <div class="menu_title parent_cat_name"> <h6><?php echo $category->name; ?></h6> </div> <?php rs_left_menu_subcats($subcategories); ?> </nav> </div>
I would like do display the another menu if site is homepage. In other cases it should be menu from code I pasted.
What code may I use?
-
Pat about 8 yearsLooks good, but after use it I don't see no additional menu. I try with only "test" text too and it is also invisible.
-
pes502 about 8 years@Pat and in Wordpress administration, which site you using as homepage? Standard WP page with posts, or some static page?
-
Pat about 8 yearsI use static page.
-
pes502 about 8 yearsThen use only
is_front_page()
in the conditional, so first line of my code must be:<?php if( is_front_page() ) { ?>