简体   繁体   English

在WordPress管理员中添加菜单

[英]Add Menu in WordPress Admin

I'm trying to add a top level menu to the left sidebar of the WordPress admin panel. 我正在尝试在WordPress管理面板的左侧栏中添加一个顶层菜单。

Here's the code I currently have: 这是我目前拥有的代码:

add_action( 'admin_menu', 'linked_url' );
function linked_url() {
add_menu_page( 'linked_url', 'Menu Title', 'read', 'my_slug', '', 'dashicons-text', 1 );
}

add_action( 'admin_menu' , 'linkedurl_function' );
function linkedurl_function() {
global $menu;
$menu[1][2] = "https://www.example.com";
}

This code DOES work and links the menu to an external page ( https://www.example.com ). 此代码可以正常工作,并将菜单链接到外部页面( https://www.example.com )。

I learned how to do this from here: http://www.techedg.com/2014/09/06/5575/a-simple-way-to-add-an-external-link-to-the-wordpress-admin-menu/ 我从此处了解了如何执行此操作: http : //www.techedg.com/2014/09/06/5575/a-simple-way-to-add-an-external-link-to-the-wordpress-admin -菜单/

However, I can't figure out how to make the external link open in a new tab. 但是,我不知道如何在新标签页中打开外部链接。 I'd prefer than a new tab/window is opened so people don't lose what they already have open in their admin area. 我希望打开一个新的选项卡/窗口,这样人们就不会丢失自己在管理区域中已经打开的内容。

Is there something I need to change or add? 我需要更改或添加某些内容吗? Or is it just not possible? 还是只是不可能?

Did you try: 你试过了吗:

add_action( 'admin_menu' , 'linkedurl_function' );
function linkedurl_function() {
global $menu;
$menu[1][2] = "https://www.example.com target=\"_blank";
}

So then the opening and closing " (double quotation) tags are already there, and we only need an attribute added, hence we do that by adding to the current string, while escaping the opening double quotation. 因此,开头和结尾的“(双引号)标记已经存在,并且我们只需要添加一个属性,因此我们可以通过添加到当前字符串中来实现这一点,同时转义开头的双引号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM