WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to add a link, in the Admin Sidebar, that links to one of the pages I've created in the PAGES section. For example, I've created an ABOUT page. So in the sidebar I would like a link to "About" that loads this link: post.php?post=7&action=edit

Why? I am trying to do this because I am working on a website that has 4 custom posts types and 3 pages. The custom post types have admin menu links, so I think it would be a better user experience if the 3 pages also had direct links in the sidebar, instead of needing to click PAGES and then seeing the list of 3 pages and having to click "EDIT" (and then I would hide the PAGES section link from the admin menu).

I was headed down this road, but it doesn't seem to be what I want/need (I can't get it to link to where I want): http://codex.wordpress.org/Administration_Menus#Inserting_the_Pages

share|improve this question
up vote 1 down vote accepted

To dynamically add menu items you can use WP_Query, specifically get_posts or get_pages. Get pages is more consistent. Here's an example to add all pages to the Pages admin menu. You can change paramaters to exclude, include, orderby, etc in the $args below. To change to a custom post type just change $custom variable to your post type name.

/* All Pages Dropdown List */

if ( !function_exists( 'admin_menu_links_to_all_edit_post_type_custom' ) ) {
function admin_menu_links_to_all_edit_post_type_custom() {
    if ( !is_admin() ) // Only Run if On Admin Pages

     $custom = 'page';  // Change this to your custom post type slug ( So for "http://www.example.com/wp-admin/edit.php?post_type=recipes" you would change this to 'recipes'  )

      // Full List of Paramaters - http://codex.wordpress.org/Template_Tags/get_posts
      $args = array(
          'orderby'          => 'modified', //Orderr by date , title , modified, etc
          'order'            => 'DESC', // Show most recently edited on top
          'post_type'        => $custom, // Post Type Slug
          'numberposts'      => -1,  // Number of Posts to Show (Use -1 to Show All)
          'post_status'      => array('publish', 'pending', 'draft', 'future', 'private', 'inherit'),
      $types = get_posts( $args ); // Get All Pages
      foreach ($types as $post_type) {
      add_submenu_page( // add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function );
        , esc_attr(ucwords($post_type->post_title)) // Get title, remove bad characters, and uppercase it
        , esc_attr(ucwords($post_type->post_title)) // Get title, remove bad characters, and uppercase it
        , 'edit_posts' // Require Edit Post/Page/Custom Capability
        , 'post.php?post=' . $post_type->ID . '&action=edit' // Get the page link by its id
        , '' // No function callback
add_action('admin_menu', 'admin_menu_links_to_all_edit_post_type_custom');

if ( !function_exists( 'admin_menu_links_to_all_edit_post_type_custom_css' ) ) {
    function admin_menu_links_to_all_edit_post_type_custom_css() {
<style type="text/css">
ul#adminmenu li.wp-has-submenu > ul.wp-submenu.wp-submenu-wrap {
max-height: 700px;
overflow-x: scroll;
    add_action('admin_head', 'admin_menu_links_to_all_edit_post_type_custom_css');

Or to just add individually:

/* Single URL Submenu */

if ( !function_exists( 'single_submenu_dropdown_link_example' ) ) {
function single_submenu_dropdown_link_example() {
    global $submenu;
    $link_to_add = 'post.php?post=7&action=edit';
    // change edit.php to the top level menu you want to add it to 
    $submenu['edit.php'][] = array('About', 'edit_posts', $link_to_add);
add_action('admin_menu', 'single_submenu_dropdown_link_example');

This will add toplevel admin menus to your other pages:

/* Toplevel Page Menus */

if ( ! function_exists( 'toplevel_admin_menu_pages' ) ) {
function toplevel_admin_menu_pages(){
if ( !current_user_can('administrator') ) {  // If the user is not the administrator remove and add new menus
    remove_menu_page( 'index.php' );                  //Dashboard
    remove_menu_page( 'edit.php' );                   //Posts
    remove_menu_page( 'upload.php' );                 //Media
    remove_menu_page( 'edit.php?post_type=page' );    //Pages
    remove_menu_page( 'edit-comments.php' );          //Comments
    remove_menu_page( 'themes.php' );                 //Appearance
    remove_menu_page( 'plugins.php' );                //Plugins
    remove_menu_page( 'users.php' );                  //Users
    remove_menu_page( 'tools.php' );                  //Tools
    remove_menu_page( 'options-general.php' );        //Settings
    add_menu_page( 'Home', 'Home', 'edit_posts', 'post.php?post=39&action=edit', '', 'dashicons-admin-home', 6 );
    add_menu_page( 'About', 'About', 'edit_posts', 'post.php?post=15&action=edit', '', 'dashicons-editor-help', 7 );
    add_menu_page( 'Services', 'Services', 'edit_posts', 'post.php?post=24&action=edit', '', 'dashicons-admin-tools', 8 );
add_action( 'admin_menu', 'toplevel_admin_menu_pages' );
share|improve this answer
Thanks Willow. I will try this now but I see this is going to add a submenu under an existing section. I am looking to add the pages links as top-level menu items - so instead of having Dashboard, Pages, Posts, Comments...I would like to have my pages listed About, Services, Contact, etc. Is this possible with an adjustment to your code? – codeview Jul 28 '14 at 16:03
Oh I got ya. I thought you wanted certain post types pages as sub menus to that post type. Yea thats even easier you just use add_menu_page. I changed the answer. – Bryan Willis Jul 28 '14 at 21:47
Also current_user_can checks which user is active so this will only change for people not administrator. If you want to change for yourself to just delete that part. – Bryan Willis Jul 28 '14 at 21:52
Ah! Thank you, Willow. That is exactly what I need. I was actually already using the add_action('admin_menu') function to remove_menu_page's. I'm having trouble reordering the menu now, though. I am using the menu_order function already but I don't know what to put in for a new line, for example, to have the new ABOUT link at the top? – codeview Jul 28 '14 at 22:31
function wpse_menu_order($menu_ord) { if (!$menu_ord) return true; return array( 'index.php', // Dashboard 'separator1', // First separator '_____________', // About? 'edit.php?post_type=event', // Custom Post Type: event ); } add_filter('custom_menu_order', 'wpse_menu_order'); // Activate wpse_menu_order add_filter('menu_order', 'wpse_menu_order'); – codeview Jul 28 '14 at 22:31
if ( !function_exists( 'wp_toolbar_frontend_admin_menu_links_extras' ) ) {

function wp_toolbar_frontend_admin_menu_links_extras($wp_admin_bar) {   
    if ( is_admin() || !is_admin_bar_showing() )

   if ( !current_user_can('edit_pages') ) 

        'id' => 'homepage',
        'title' => 'Home',
        'href' => admin_url() . 'post.php?post=39&action=edit' ,
        'parent' => 'site-name',
        'meta' => array(
            'class' => 'homepage'

        'id' => 'aboutus',
        'title' => 'About',
        'href' => admin_url() . 'post.php?post=36&action=edit' ,
        'parent' => 'site-name',
        'meta' => array(
            'class' => 'aboutus'

        'id' => 'services',
        'title' => 'Services',
        'href' => admin_url(). 'post.php?post=32&action=edit' ,
        'parent' => 'site-name',
        'meta' => array(
            'class' => 'services'

    add_action('admin_bar_menu', 'wp_toolbar_frontend_admin_menu_links_extras', 99);

share|improve this answer
You can also try this one which will add those links to the front end toolbar as a submenu to the Dashboard link. Very convenient. – Bryan Willis Jul 28 '14 at 22:15
Just saw your comment that this is for frontend admin toolbar. Thank you. I actually removed it with this: show_admin_bar(false); for this particular project (trying to really streamline Wordpress for this particular project) but it may come in handy for others. – codeview Jul 28 '14 at 22:42
Hey no prob... By the way, I personally try to do this kind of stuff without a plugin, but wordpress.org/plugins/admin-menu-editor is preferable than coding for a lot of people on this – Bryan Willis Jul 29 '14 at 22:08

Your Answer


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.