简体   繁体   中英

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.

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 ?

The short answer is that this is not possible to do using the add_menu_page() function. Probably for good reason, Wordpress does not allow external links in its admin menu. 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.

This code comes from this site which also has more details on how to customize it. Including advice on changing the menu placement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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