I am making a theme for wordpress that makes it in to an app.
I would like the menu items below to show up when runned in header.php – however it only shows up if I activate a new menu with at least one item as primary menu.
I want a user to be able to install wordpress and then just activate the theme (without having to config a menu manually).
Can I add the items below without having to do the procedure of activating a primary menu? Or any other good workaround.
add_filter( 'wp_nav_menu_items', 'add_links', 10, 2 );
function add_links( $items, $args ) {
$items = "";
$items .= '<li><a href="'. site_url() .'">Hem</a></li>';
$items .= '<li><a href="'. site_url('about-us') .'">About-us</a></li>';
return $items;
}
wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu' ) );
Take a look at the
fallback_cb
parameter of thewp_nav_menu
function. Here’s a nice explanation: https://wordpress.stackexchange.com/a/64526/25765