I do a lot of WordPress theme development and one thing that I don’t like is having to push many buttons to go back to the category list. When I am editing a category and I have 10 posts or more to edit. I wanted one button that would take me back to the list of posts in that category. Below is a code snippet that will allow you to do just that. It will add a “back” button in the posts menu when you are in the edit screen of a post that belongs to a category.


add_action( 'admin_menu', 'add_custom_submenus', 9999 );
function add_custom_submenus()
{
global $submenu;

if( isset($_GET[‘post’]) && get_post($_GET[‘post’]) && isset($_GET[‘action’]) && ‘edit’ == $_GET[‘action’] )
$post = get_post($_GET[‘post’]);

if( isset($post)
&& !empty($post->post_type)
&& is_object_in_taxonomy($post->post_type, ‘category’)
){
foreach ( (array) get_the_category($post->ID) as $cat )
{
if ( empty($cat->slug ) )
continue;

$submenu[‘edit.php’][] = array(
__(‘Back’), // menu title
‘edit_posts’, // menu cap
‘edit.php?category_name=’ . $cat->slug // menu link
);
}
}
}