当你看的时候at the possible arguments, 然后您会看到,还有一个选项可以添加自定义导航菜单walker
班
$defaults = array(
\'theme_location\' => \'\',
\'menu\' => \'\',
\'container\' => \'div\',
\'container_class\' => \'\',
\'container_id\' => \'\',
\'menu_class\' => \'menu\',
\'menu_id\' => \'\',
\'echo\' => true,
\'fallback_cb\' => \'wp_page_menu\',
\'before\' => \'\',
\'after\' => \'\',
\'link_before\' => \'\',
\'link_after\' => \'\',
\'items_wrap\' => \'<ul id="%1$s" class="%2$s">%3$s</ul>\',
\'depth\' => 0,
\'walker\' => \'\'
);
wp_nav_menu( $defaults );
walker的实现方式如下:
$walker = new WPSE90265_Nav_Menu_Walker();
wp_nav_menu( array(
# ...
\'walker\' => $walker
# ...
) );
它应该扩展默认的导航菜单漫游器,以便您只需覆盖需要重新定义的那些方法:
class WPSE90265_Nav_Menu_Walker extends Walker_Nav_Menu
{
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 )
{
if ( ! is_user_logged_in() )
$output = str_replace(
\'class="\'
,\'disabled class="\'
,$output
);
parent::start_el( $output, $item, $depth, $args, $id );
}
}
请注意
disabled
参数仅适用于特定的HTML元素/标记。请对其进行搜索,并根据其更改您的助行器。您也可以尝试添加
onClick="return false;"
如果无法使用此类标签,则在助行器内部。