This may sound weird, but I need to add different menu items to two specific menu types. When I mean different menu items, I mean, the items I set to main (header) menu are only for that menu and the same thing for footer menu. So, the menu items from primary-menu shouldn't appear on secondary-menu and vice-versa, despite how similar they seem to be.
add_filter('wp_nav_menu_items', 'register_primary_menu_items', 10, 2);
if (!function_exists('register_primary_menu_items')) {
function register_primary_menu_items($items, $args) {
if ( $args->menu = 'primary-menu' ) {
$items .= "\n" . "\t\t\t\t\t\t" . '<li><a href="#home">Home</a></li>' . "\n" .
"\t\t\t\t\t\t" . '<li><a href="#main">Who are We</a></li>' . "\n" .
"\t\t\t\t\t\t" . '<li><a href="#service">Services</a></li>' . "\n" .
"\t\t\t\t\t\t" . '<li><a href="#contact">Contacts</a></li>' . "\n";
//return $items;
}
/*
if ( $args->theme_location = 'secondary-menu' ) {
$items = '<li><i class="fa fa-angle-right"></i><a href="#home">Home</a></li>' . "\n" .
'<li><i class="fa fa-angle-right"></i><a href="#main">Who are We</a></li>' . "\n" .
'<li><i class="fa fa-angle-right"></i><a href="#service">Services</a></li>' . "\n" .
'<li><i class="fa fa-angle-right"></i><a href="#contact">Contacts</a></li>';
return $items;
}*/
return $items;
}
}
add_filter('wp_nav_menu_items', 'register_secondary_menu_items', 10, 2);
if (!function_exists('register_secondary_menu_items')) {
function register_secondary_menu_items($items, $args) {
if ( $args->menu = 'secondary-menu' ) {
$items = "\n" . "\t\t\t\t\t\t" . '<li><i class="fa fa-angle-right"></i><a href="#home">Home</a></li>' . "\n" .
"\t\t\t\t\t\t" . '<li><i class="fa fa-angle-right"></i><a href="#main">Who are We</a></li>' . "\n" .
"\t\t\t\t\t\t" . '<li><i class="fa fa-angle-right"></i><a href="#service">Services</a></li>' . "\n" .
"\t\t\t\t\t\t" . '<li><i class="fa fa-angle-right"></i><a href="#contact">Contacts</a></li>' . "\n";
//return $items;
}
return $items;
}
}
That is the code I'm currently using, but it doesn't do what I want. Instead it sets the same menu items from secondary-menu on both header and footer menu or the inverse.
$args->menu = 'primary-menu'
. This is setting$args->menu
toprimary-menu
, and then later on you're setting it tosecondary-menu
. If you want to compare values you need to use===
: php.net/manual/en/language.operators.comparison.php