Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to remove a menu item and tried several approaches, but have not had any luck. It was created from a FAQ plugin.

If I use this line:

remove_menu_page( 'edit.php?post_type=question' );

It will remove the main menu, however I only want to remove two sub-menu items contained inside that edit.php?post_type=question URL address.

For the item I want to remove, the path in the URL bar gives me the following:
edit-tags.php?taxonomy=faq-topic&post_type=question
and
edit-tags.php?taxonomy=faq-tags&post_type=question

I have tried several solutions including remove_menu_page and remove_submenu_page to no avail.

What has failed so far:

remove_submenu_page( 'edit.php?post_type=question', 'edit-tags.php?taxonomy=faq-topic&post_type=question');
remove_menu_page( 'edit-tags.php?taxonomy=faq-tags') ;
remove_menu_page( 'edit-tags.php?taxonomy=faq-tags&post_type=question') ;
remove_submenu_page( 'edit.php?post_type=question', 'edit-tags.php?taxonomy=faq-topic&post_type=question');
remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=faq-topic&post_type=question');
remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=faq-topic');
remove_submenu_page( 'edit.php', 'edit-tags.php');
share|improve this question
    
Can you show some of the code that you have tried? –  Pat J Apr 15 '13 at 1:45
    
I added it to the top to make it cleaner. –  John Apr 15 '13 at 1:51
    
Were you using your remove_submenu_page() and remove_menu_page() calls inside an action hook? See the example on the Codex page. –  Pat J Apr 15 '13 at 1:53
    
Yes I was using it inside an action hook. add_action( 'admin_menu', 'my_remove_menu_pages' ); function my_remove_menu_pages() { /*those functions here*/ } –  John Apr 15 '13 at 2:06
add comment

1 Answer

up vote 5 down vote accepted
function remove_submenu() {

    remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=faq-topic&post_type=question' );
    remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=faq-tags&post_type=question' );
}

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

Please read the Codex. remove_submenu_page() need two parameters and the right hook.

And very important: Use a very, very, very high priority in your hook! If you use a low priority, your function will be executed before the menus will be added. So there is no menu to remove. If you use a high priority, there is a good chance that your function will be executed after the menus was added.

This could be the tricky part.

UPDATE

After installing and inspecting the plugin, I found the solution. There are several issues and a few tricky parts.

The submenus are not added with add_submenu_page(), they are added with a custom post type. A simple search by add_submenu_page(), copy the menu slugs and removing the menus have to fail. I have to search for the cpt slug and use it.

After global $submenu; var_dump( $submenu ); I get this output

[more elements]
    'edit.php?post_type=question' => 
        array (size=7)
          5 => 
            array (size=3)
              0 => string 'FAQs' (length=4)
              1 => string 'edit_posts' (length=10)
              2 => string 'edit.php?post_type=question' (length=27)
          10 => 
            array (size=3)
              0 => string 'Neue FAQ' (length=8)
              1 => string 'edit_posts' (length=10)
              2 => string 'post-new.php?post_type=question' (length=31)
          15 => 
            array (size=3)
              0 => string 'FAQ Titel' (length=9)
              1 => string 'manage_categories' (length=17)
              2 => string 'edit-tags.php?taxonomy=faq-topic&post_type=question' (length=55)
          16 => 
            array (size=3)
              0 => string 'FAQ Tags' (length=8)
              1 => string 'manage_categories' (length=17)
              2 => string 'edit-tags.php?taxonomy=faq-tags&post_type=question' (length=54)
[ more elements ]

Now it was easy to remove the submenus with edit.php?post_type=question as menu slug and edit-tags.php?taxonomy=faq-topic&post_type=question / edit-tags.php?taxonomy=faq-tags&post_type=question as submenu slug.

If you watch carefully, the ampersand (&) is a html entity. It's not possible just to copy the url part and insert it. So you cannot remove a submenu page with a un-encoded url, it have to be url-encoded.

And here is the final code:

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

function remove_faq_subpages() {

    $ptype = 'question';
    remove_submenu_page( "edit.php?post_type={$ptype}", "edit-tags.php?taxonomy=faq-tags&post_type={$ptype}" );
    remove_submenu_page( "edit.php?post_type={$ptype}", "edit-tags.php?taxonomy=faq-topics&post_type={$ptype}" );

}
share|improve this answer
    
Unfortunately that didn't work either. The following screenshot will be extremely helpful. I tried to do it a different way... using the variables in the screenshot, but couldnt get it to work. s7.postimg.org/7m36rciob/this_might_help.jpg –  John Apr 15 '13 at 2:18
    
Here is a better screenshot, sorry it got clipped short s17.postimg.org/uj18k5vvz/FAQ_help.jpg –  John Apr 15 '13 at 2:21
2  
Open the plugin, find the line where the menus will be added with add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function );. Use the $parent_slug and $menu_slug to remove the submenus. –  Ralf912 Apr 15 '13 at 2:23
1  
I went the easy route and found a plugin that was able to do it. I used Adminimize and was easily able to do it. –  John Apr 17 '13 at 0:35
1  
After all, I found the reasons why all solutions failed. At first it was a custom post type and not an submenu page. And the url have to be url-encoded. The plain ampersand (&) in the url won't work. –  Ralf912 Apr 17 '13 at 15:21
show 5 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.