Skip to content
Advertisement

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 ?

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement