add_page_menu to make shortcut to widgets

I want to make a menu button that takes me to wp-admin/widgets.php. The above code seems to work only partially.

add_action( 'admin_menu', 'register_widgets_menu_button' );

function register_widgets_menu_button(){
  add_menu_page( 'Widgets', 'Widgets', 'manage_options', 'widgets', 'my_custom_menu_page', plugins_url( 'myplugin/images/icon.png' ), 6 );
}

function my_custom_menu_page(){
  include ( 'widgets.php' );

I get to the widgets page, but in a peculiar way. Here is the URL that I see in the address bar:

wp-admin/admin.php?page=widgets

But there is a PHP error breaking the page (I can’t see all the widgets). Here is the error:

Notice: Undefined variable: wp_registered_sidebars in htdocs/wp-admin/widgets.php on line 403

1 Answer
1

You can add a link to the widgets.php like that:

add_action( 'admin_menu', 'f711_add_widgets_shortcut', 999 );

function f711_add_widgets_shortcut() {

    add_menu_page( 'Widgets', 'Widgets', 'publish_pages', 'widgets.php', '', '', 61 );

}

Be sure to check your permission settings, and you may also include another image. You can find the documentation about the function at The Codex.

Leave a Comment