文章目录[隐藏]

新增后台顶部导航栏菜单

示例如下:

WordPress admin_bar的开发
对应的代码如下:

//添加admin_bar
function add_anticode_admin_bar_item($wp_admin_bar) {
    $args = array(
        'id'    => 'anticode_admin_bar_item',
        'title' => '防伪码',
        'href'  => admin_url('admin.php?page=fwmpage'),
        'meta'  => array(
            'class' => 'anticode-admin-bar-item',
        ),
    );
    $wp_admin_bar->add_node($args);
    
  $wp_admin_bar->add_menu(
    array(
      'parent' => "anticode_admin_bar_item",
      'title'  => '防伪码列表',
      'id'     => 'fwmpage',
      'href'   => admin_url( 'admin.php?page=fwmpage' ),

    )
  );
  $wp_admin_bar->add_menu(
    array(
      'parent' => "anticode_admin_bar_item",
      'title'  => '插件设置',
      'id'     => 'anticode_option',
      'href'   => admin_url( 'admin.php?page=anticode_option' ),

    )
  );
  $wp_admin_bar->add_menu(
    array(
      'parent' => "anticode_admin_bar_item",
      'title'  => '页面模板',
      'id'     => 'anti_templates',
      'href'   => admin_url( 'edit.php?post_type=anti_templates' ),

    )
  );
}
add_action('admin_bar_menu', 'add_anticode_admin_bar_item',999);

发表回复

后才能评论