TechWordPressHow to Add Custom Menu in WordPress Dashboard for All the Users?

How to Add Custom Menu in WordPress Dashboard for All the Users?

WordPress grants the rights to customize anything through hard-coding and plugins, but there are situations when you may not be able to achieve the desired results as expected; the same thing goes with adding Custom Menu Page in WordPress that can be viewed by all the Users on the website and not just only by the users with administrator rights and privileges.

Highlights of this article: 

  • Adding Custom menu / pages in WordPress Dashboard
  • Adding Custom sub-menu / sub-pages in WordPress Dashboard
  • Adding Custom menu / pages in WordPress Dashboard with External URL

To add the custom menu or the sub menu in WordPress dashboard we would be placing a piece of PHP source code in the functions.php file of your current theme or the child-theme (highly recommended). Adding anything in the main theme may vanish after updating the theme and the reason you are always advised to create a child-theme of your current theme for making any kind of modification on your WordPress powered website.

The WordPress themes directories are generally located at WordPress-Installation-Directory/wp-content/themes/YOUR-THEME until you’ve not customize it using some security plugins or manually.

add_action( 'admin_menu', 'add_menu_to_db',);
function add_menu_to_db() {
add_posts_page( 'Custom Menu Title', 'Title', 'manage_options', 'PATH/URL', '', '', 1);
}

The above piece of PHP code will add a sub-menu under the Posts option of your WordPress dashboard, but the problem with this code is, the menu will be only viewable to users with administrator rights.

To enable all other users to see and access the custom menu you have to change manage_options to either read or exist in the above code, so the final code will be:

add_action( 'admin_menu', 'add_menu_to_db',);
function add_menu_to_db() {
add_posts_page( 'Custom Menu Title', 'Title', 'read', 'PATH/URL', '', '', 1);
}

Similarly, you can add the custom menus under the main menu or anywhere else of the WordPress dashboard by changing add_posts_page to the function (as given below) where you want to display the menu.

add_function_page( $page_title, $menu_title, $capability, $menu_slug, $function );
  1. add_function_page: Use any of the function from the below table
  2. $page_title: You can replace it with your desired title
  3. $menu_title: You can replace it with your menu title
  4. $capability: You can choose from manage_options or read / exit
  5. $menu_slug: (Optional)
  6. $function: (Optional)
FunctionDescription
add_posts_page()Adds sub-menu under Posts option
add_dashboard_page()Adds menu in the main Dashboard
add_media_page()Adds sub-menu under Media option
add_links_page()Adds sub-menu under Links option
add_pages_page()Adds sub-menu under Pages option
add_comments_page()Adds sub-menu under comments page
add_theme_page()Adds sub-menu under themes menu
add_plugins_page()Adds sub-menu under plugins menu
add_users_page()Adds sub-menu under users menu

How to add Menu or Sub-menu in WordPress with External URL?

Use any of the above Source-code to add the menu or sub menu in the WordPress dashboard and Install the “Safe Redirect Manager” plugin from the WordPress Plugin center to redirect to an external URL.

IR Media Team
IR Media Team
IR Media Team is a member of Digital Pradesh News Networks, a collective of journalists, reporters, writers, editors, lawyers, advocates, professors, and scholars affiliated with the Digital Pradesh News Networks.

Latest Updates