wp_nav_menu_items for one menu
Question
I tested this tutorial. It works great.
The problem is that in the tutorial there is one menu while I have 2 menus.
Let me know how I can customize this function for the feature only applies to primary menu.
The code :
function new_nav_menu_items($items) {
$items = "";
$args = array(
"post_type" => "page",
"order" => "ASC",
"orderby" => "menu_order"
);
$the_query = new WP_Query($args);
if($the_query->have_posts()):
while($the_query->have_posts()):
$the_query->the_post();
$items .= '<li><a href="#post-'. get_the_ID() .'">' . get_the_title() . '</a></li>';
endwhile;
else:
echo "";
endif;
return $items;
}
add_filter("wp_nav_menu_items", "new_nav_menu_items");
I tried with if( $args->theme_location == 'primary' )
but I do not know how to use it ..
I can not apply this one
0
menus
3 years
2020-06-09T15:10:21-05:00
2020-06-09T15:10:21-05:00 0 Answers
104 views
0
Leave an answer