首页 文章

在WordPress中添加管理菜单分隔符

提问于
浏览
3

我正在尝试创建一个管理菜单分隔符,允许您将它们放入代码中 . 这是功能:

function add_admin_menu_separator($position) {
    global $menu;
    $index = 0;
    foreach($menu as $offset => $section) {
        if (substr($section[2],0,9)=='separator')
        $index++;
        if ($offset>=$position) {
            $menu[$position] = array('','read',"separator{$index}",'','wp-menu-separator');
            break;
        }
    }
    ksort( $menu );
}

添加操作位如下所示

add_action('admin_init','admin_menu_separator');

function admin_menu_separator() {add_admin_menu_separator(220);}

它工作正常但在重新排列菜单时会在WordPress中产生以下错误:

警告:在第174行的/home/user/public_html/wp-creation.com/wp-content/themes/liquid_theme_0.4_licensed/functions.php中为foreach()提供的参数无效警告:ksort()期望参数1为数组,null在第182行的/home/user/public_html/wp-creation.com/wp-content/themes/liquid_theme_0.4_licensed/functions.php中给出

1 回答

  • 3

    你应该挂钩 admin_menu

    add_action('admin_menu','admin_menu_separator');
    

    并使用低于 220 的东西 . 我的系统中最大的 offset99 .

    检查this very fine class以处理管理员菜单 .
    它出现在这个WPSE问题中:Add a Separator to the Admin Menu?

相关问题