{"id":5093,"date":"2018-02-10T14:27:00","date_gmt":"2018-02-10T19:27:00","guid":{"rendered":"https:\/\/themespress.ca\/?p=5093"},"modified":"2022-10-01T14:41:28","modified_gmt":"2022-10-01T18:41:28","slug":"wordpress-hiding-a-sub-menu-with-a-plugin","status":"publish","type":"post","link":"https:\/\/themespress.ca\/en\/wordpress-hiding-a-sub-menu-with-a-plugin\/","title":{"rendered":"WordPress: Hiding a Sub-Menu with a Plugin"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><div class=\"vc_row wpb_row vc_row-fluid\"><div class=\"wpb_column vc_column_container vc_col-sm-12\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>With this tutorial, we will show you how to hide a sub-menu with a plugin we&#8217;re developing all the while keeping the slugs intact if required for developed plugin. (<a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/add_submenu_page\/\" target=\"_blank\" rel=\"noopener\">add_submenu_page<\/a>)<\/p>\n<p>First, we need a menu and a sub-menu for our WordPress plugin.<br \/>\nLet&#8217;s take a look at the function below; we see that the plugin has a Main Tab and Sub-Menu tab that are displayed on the WordPress dashboard with the name of the plugin.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-3297998\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-3297998\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"php\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ Menu Plugin Wordpress \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\nadd_action(&#039;admin_menu&#039;, &#039;fonction_menu_page&#039;);\nfunction fonction_menu_page() {\n   add_menu_page( &#039;Titre Du Plugin&#039;, &#039;Titre Du Plugin&#039;, &#039;manage_options&#039;, &#039;slug-du-plugin&#039;, &#039;nomdelafonction&#039;, &#039;&#039;,2);\n   add_submenu_page(&#039;slug-du-plugin&#039;, &#039;Titre Du Sous Menu Plugin&#039;, &#039;Titre Du Sous Menu Plugin&#039;, &#039;manage_options&#039;, &#039;slug-du-sous-menu&#039;, &#039;autrenomdelafonction&#039;);\n}<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>We want to keep our Main page of the WordPress plugin, but if we want we can hide the sub-menu.<\/p>\n<p>In order to do so, simply add <strong>null<\/strong> in add_submenu_page. This allows us to keep the sub-menu slug in a tab or navigation item of our plugin.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<h2 style=\"text-align: left\" class=\"vc_custom_heading vc_do_custom_heading\" >WordPress : Cacher un Sous-Menu Plugin<\/h2>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>Here&#8217;s the same function with the hidden sub-menu thanks to the null.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-9431798\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-9431798\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"php\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ Menu Plugin Wordpress \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\nadd_action(&#039;admin_menu&#039;, &#039;fonction_menu_page&#039;);\nfunction fonction_menu_page() {\n   add_menu_page( &#039;Titre Du Plugin&#039;, &#039;Titre Du Plugin&#039;, &#039;manage_options&#039;, &#039;slug-du-plugin&#039;, &#039;nomdelafonction&#039;, &#039;&#039;,2);\n   add_submenu_page( null, &#039;slug-du-plugin&#039;, &#039;Titre Du Sous Menu Plugin&#039;, &#039;Titre Du Sous Menu Plugin&#039;, &#039;manage_options&#039;, &#039;slug-du-sous-menu&#039;, &#039;autrenomdelafonction&#039;);\n}<\/pre><\/div><\/div><\/div><\/div><\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"With this tutorial, we will show you how to hide a sub-menu with a plugin we're developing all the while keeping the slugs intact if required for developed plugin. (add_submenu_page)<div class=\"read-more\"><a class=\"btn button-secondary\" href=\"https:\/\/themespress.ca\/en\/wordpress-hiding-a-sub-menu-with-a-plugin\/\">Read More<\/a><\/div>","protected":false},"author":81,"featured_media":5095,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[283],"tags":[313],"class_list":["post-5093","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-plugins"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/5093","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/users\/81"}],"replies":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/comments?post=5093"}],"version-history":[{"count":0,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/5093\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media\/5095"}],"wp:attachment":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media?parent=5093"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/categories?post=5093"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/tags?post=5093"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}