Where are unwanted values loaded from in an empty WordPress menu location?
-
I am designing a WordPress theme and I have encountered a strange issue with the menus. I do not use the cache plugin in WordPress and the browser cache has been checked and there is no problem with this issue. I am developing the theme on xampp. I have defined two positions in my theme, one for the main menu position and the other for the top menu position. If one or both of these positions are empty, values ??are displayed that I do not know where they are loaded from. I added a filter to the function file so that if the user leaves the menu position empty, a specific phrase is displayed in it so that the theme style does not get messed up, and this filter also has no effect on displaying these values!
in functions.php
function liberty_setup_theme(){
//addind dynamic menus
register_nav_menus(
array(
'main-menu' => __( '?????? ????? ????' ),
'top-menu' => __( '?????? ????? ????? ????' )
)
);
}
add_action('after_setup_theme', 'liberty_setup_theme');// ?????? ????? ???? ????? ?????? ??????? add_filter( 'wp_nav_menu', 'custom_default_menu', 10, 2 ); function custom_default_menu( $nav_menu, $args ) { // ????? ???? ?? ??? ??? ???? ??? ? ??? ?????? ???? ???? ??? ??? if ( empty( $nav_menu ) && $args->theme_location == 'top-menu' ) { return '<div class="default-menu">???? ??????? ???</div>'; } return $nav_menu; }
in header.php
<div class="topbar-left"> <nav class="top-menu-nav"> <?php wp_nav_menu(array('theme_location' => 'top-menu', 'container' => '', 'menu_class' => 'top-menu-class')); ?> </nav> <ul class="topbar-icons"> <li><i class="fas fa-shopping-bag"></i></li> <li><i class="fas fa-search"></i></li> </ul> </div>
- You must be logged in to reply to this topic.