简体   繁体   English

如何在wordpress中使用url而不是slug添加主菜单url?

[英]How to add main menu url with a url instead of slug in wordpress?

I have used the following function to add menu in wordpress admin backend.我使用以下功能在 wordpress 管理后端添加菜单。

add_menu_page(
    __( 'Golf courses', 'golf_courses' ),
    'Golf courses',
    'manage_options',
    'golf_courses',
    'golf_courses',
    plugins_url( 'myplugin/images/icon.png' ),
    6
    );

But i cant able to add url eg: http://www.google.com in menu href any solution for this ?但我无法添加网址,例如: http : //www.google.com in menu href 对此有任何解决方案吗?

The short answer is that this is not possible to do using the add_menu_page() function.简短的回答是使用add_menu_page()函数无法做到这add_menu_page() Probably for good reason, Wordpress does not allow external links in its admin menu.可能有充分的理由,Wordpress 不允许在其管理菜单中使用外部链接。 You can, however, sneak into the admin menu preparation hook and alter the global variable that stores the contents of the admin menu.但是,您可以潜入管理菜单准备挂钩并更改存储管理菜单内容的全局变量。

I believe this is will do what you want:我相信这会做你想做的:

    add_action('admin_menu', 'example_admin_menu');

/**
* add external link to Tools area
*/
function example_admin_menu() {
    global $submenu;
    $url = 'http://www.example.com/';
    $submenu['tools.php'][] = array('Example', 'manage_options', $url);
}

You will want to alter: $submenu['tools.php'][] based on where you want to place the menu.您将需要更改: $submenu['tools.php'][]基于您想要放置菜单的位置。

This code comes from this site which also has more details on how to customize it.此代码来自此站点该站点还提供了有关如何自定义它的更多详细信息。 Including advice on changing the menu placement.包括更改菜单位置的建议。

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

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