I’m trying to have the menu link per default when using my custom menus, and in my functions.php
document I have this:
function home_page_menu_args( $args ) {
$args['show_home'] = true;
return $args;
}
add_filter( 'wp_page_menu_args', 'home_page_menu_args' );
The thing is, in the custom menu options > pages I have this: “No items.” So not sure what’s going on, it was working in other websites but not in this one, any idea?
First, I’ll assume that you have custom nav menus properly configured:
register_nav_menus()
infunctions.php
, to definetheme_location
valueswp_nav_menu()
calls in the template, withtheme_location
called in the args arrayIf that’s the case, then the issue is that you’re using the wrong filter. The
wp_page_menu_args
filter is applied inside ofwp_page_menu()
, which is the default callback forwp_nav_menu()
when no menu is assigned to the indicatedtheme_location
.The output of
wp_nav_menu()
applies its own filter:wp_nav_menu_args
. So you’ll need to hook your callback into that filter as well:That way, the
show_home
arg will return true for bothwp_page_menu()
output and forwp_nav_menu()
output.Be careful with
wp_nav_menu()
, though; if the user adds a home link to the custom menu, then two home page links will be displayed in the rendered menu.