If this is about specifying your $theme_location
for wp_nav_menu()
, than it should be enough to check if it is the right location. And only than modify the $args
of the _menu_per_page()
function, which is used as callback for the wp_nav_menu_args
filter. So the function looks like this:
function _menu_per_page( $args ) {
if(is_page()) {
// the selected menu applies to the following location
if ( $args['theme_location'] == 'sub-header-menu' ) {
global $post;
$menuslug = get_post_meta($post->ID, $this->metaname, true);
if(!empty($menuslug) && is_nav_menu($menuslug)) {
$args['menu'] = $menuslug;
} // END if(!empty($menu_name) && is_nav_menu($menu_name))
} // END if ( $args['theme_location'] == 'sub-header-menu' )
} // END if(is_page())
return $args;
} // END function _menu_per_page($args="")