我意识到有一种更简单的方法,那就是编辑我孩子的标题。php文件
子标题内。php文件查找对wp_nav_menu
包含调用的函数tesseract_output_menu
.替换对的调用tesseract_output_menu
一个新函数的child_tesseract_output_menu
.在我的孩子主题的函数中包含该函数所需的编辑版本。php文件这是我的孩子主题函数中的walker类启用函数。php文件:
function child_tesseract_output_menu( $cont, $contClass, $location, $depth ) {
switch( $location ) :
case \'primary\': $hblox = \'header\'; break;
case \'primary_right\': $hblox = \'header_right\'; break;
case \'secondary\': $hblox = \'footer\'; break;
case \'secondary_right\': $hblox = \'footer_right\'; break;
endswitch;
$locs = get_theme_mod(\'nav_menu_locations\');
$menu = get_theme_mod(\'tesseract_\' . $hblox . \'_menu_select\');
$isMenu = get_terms( \'nav_menu\' ) ? TRUE : FALSE;
$locReserved = ( $locs[$location] ) ? TRUE : FALSE;
$menuSelected = ( is_string($menu) ) ? TRUE : FALSE;
// IF the location set as parameter has an associated menu, it\'s returned as a key-value pair in the $locs array - where the key is the location and the value is the menu ID. We need this latter to get the menu slug required later -in some cases- in the wp_nav_menu params array.
if ( $locReserved ) {
$menu_id = $locs[$location]; // $value = $array[$key]
$menuObject = wp_get_nav_menu_object( $menu_id );
$menu_slug = $menuObject->slug;
};
$custSet = ( $menuSelected && ( $menu !== \'none\' ) );
if ( empty( $isMenu ) ) : //Case 1 - IF THERE\'S NO MENU CREATED -> easy scenario: no location setting, no customizer setting ( this latter only appears if there IS at least one menu created by the theme user ) => display basic menu
$walker = new Menu_With_Description;
wp_nav_menu( array(
\'theme_location\' => \'primary\',
\'menu_class\' => \'nav-menu\',
\'container_class\' => \'\',
\'container\' => FALSE,
\'depth\' => $depth,
\'walker\' => $walker
)
);
elseif ( !empty( $isMenu ) ) : //Case 2 - THERE\'S AT LEAST ONE MENU CREATED
if ( !$custSet && $locReserved ) { //no setting in customizer OR dropdown is set to blank value, location SET in Menus section => display menu associated with this location in Appearance ->
$walker = new Menu_With_Description;
wp_nav_menu( array(
// \'menu\' => $menuSlug,
\'menu\' => $menu_slug,
\'theme_location\' => $location,
\'menu_class\' => \'nav-menu\',
\'container_class\' => $contClass,
\'container\' => $cont,
\'depth\' => $depth,
\'walker\' => $walker
)
);
} else if ( !$custSet && !$locReserved ) { //no setting in customizer OR dropdown is set to blank value, location NOT SET in Menus section => display basic menu
$walker = new Menu_With_Description;
wp_nav_menu( array(
\'theme_location\' => \'primary\',
\'menu_class\' => \'nav-menu\',
\'container_class\' => \'\',
\'container\' => FALSE,
\'depth\' => $depth,
\'walker\' => $walker
)
);
} else if ( $custSet ) { //menu set in customizer AND dropdown is NOT set to blank value, location SET OR NOT SET in Menus section => display menu set in customizer ( setting a menu to the given location in customizer will update any existing location-menu association in Appearance -> Menus, see function tesseract_set_menu_location() in functions.php )
$walker = new Menu_With_Description;
wp_nav_menu( array(
\'menu\' => $menu,
\'theme_location\' => $location,
\'menu_class\' => \'nav-menu\',
\'container_class\' => $contClass,
\'container\' => $cont,
\'depth\' => $depth,
\'walker\' => $walker
)
);
}
endif;
}