You need to have a custom menu enabled in your themes before you can proceed any further. And need to add our own filter into wp_nav_menu_items hook. An example would look like this:
Example code:
add_filter( 'wp_nav_menu_items', 'your_custom_menu_item', 10, 2 );
function your_custom_menu_item ( $items, $args ) {
if (is_single() && $args->theme_location == 'primary') {
$items .= '<li>Show whatever</li>';
}
return $items;
}
As you can see, you can use the conditional statements along with the argument theme_location. This allows you to target a specific menu location with any condition you want. If you don’t want the conditional statement, you don’t have to use it. Just add it to a specific menu location or vice versa.
Thread Starter
PCWP
(@toprasobh)
It’s working for non-AMP pages. But AMP pages these menu items are not displaying.
Thread Starter
PCWP
(@toprasobh)
It worked with the amp-menu item. I was trying with primary-amp-menu.
You can create that primary-amp-menu in WordPress by visiting Appearance -> Menus in your WordPress admin area > Click on create a new menu > Provide a name for your menu in the Menu Name field and then click the Save Menu button and enable that menu as “AMP” menu.
Ref screenshot: https://prnt.sc/111jwuw