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 developing a very media-centered site with WordPress and am using the default categories and tags on uploaded media using, in part this plugin Media Categories.

I am displaying a sub-menu item under 'Media' for each 'Categories' and 'Tags' successfully using:

add_media_page( 'Tags', 'Tags', 'edit_posts' , 'edit-tags.php?taxonomy=post_tag');

It is linking through properly, but it seems somewhere in WordPress this page is assigned as a child of the default Posts type, as when I click it, it opens the 'Posts' menu and displays the Tags page, rather than keeping the 'Media' menu opened and displaying it from there. Is there any way to keep the parent page open (i.e. Media)?

This isn't an essential fix, but it would be good for the UI and continuity to have the Media menu stay open, rather than swapping to the Posts menu.

I can provide screenshots if this is confusing.

Thanks!

EDIT

I've just discovered a cheeky little definition in edit-tags.php: $parent_file = 'edit.php';

It seems each file corresponding to a submenu item in the WP Admin Menu has this $parent_file set. Now obviously, I can simply change this to 'upload.php' to refer to the Media parent, but I'm wondering if there's a non-hacky way that I can modify this value from functions.php in my theme file?

share|improve this question
add comment

2 Answers

The sub_menu_page that you are trying to open is currently linked to the Tags sub_menu_page. Hopefully, someone will find a way of making it work. I am not sure if it able to display two menu pages with the same target such as in this case. Normally you might have to remove one or rename one.

add_action('admin_menu', 'm_video_disp');

function m_video_disp() {
    global $submenu;
    $submenu['edit.php'][16][0] = 'Videos';
    // add_media_page('Welcome to Videos', 'Videos', 'manage_options', 'edit-tags.php?taxonomy=post_tag', '');
    add_submenu_page('upload.php', 'Welcome to Videos', 'Videos', 'manage_options', 'edit-tags.php?taxonomy=post_tag', '');
}

add_submenu_page('upload.php', $other_args) and add_media_page($args) do the same thing in this case. I know this answer is insufficient, I hope someone can improve on it more.

share|improve this answer
    
Thanks, but using the global $submenu (or even $menu) still leaves me with the same issue that 'edit-tags.php?taxonomy=post_tag' is somehow linked to 'edit.php' in the menu. Even if I remove the default 'Posts' type from the menu, the submenu page will not open out as a child of 'Media'. Any ideas anyone? –  lowe_22 Feb 29 '12 at 17:47
add comment

This has to be solved with jQuery. The following does it, but there are some secondary CSS effects that have to be dealt with.

menu tags moved to media

add_action( 'admin_head-edit-tags.php', 'modify_menu_highlight_wpse_43839' );

function modify_menu_highlight_wpse_43839()
{
    if( 'post_tag' == $_GET['taxonomy'] )
    {       
        ?>
        <script type="text/javascript">
            jQuery(document).ready( function($) 
            {
                $("#menu-posts").removeClass('wp-has-current-submenu'); 
                $("#menu-media").addClass('wp-has-current-submenu');
            });     
        </script>
        <?php
    }
}
share|improve this answer
add comment

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.