0

I have added custom WordPress admin menu and pages, however, I would like for it to appear in the "Appearance > Menus" section so that the user can add it in the menu structure of their website.

Please let me know how to achieve this.

Here are the sample custom menu I added on the admin page: enter image description here

Now, I wanted to add these custom pages in the Appearance > Menus of the admin section: enter image description here

I would really appreciate if someone can help.

Thanks to damienoneill2001, I was able to add taxonomy item in the Appearance > Menu, however, how do I add content inside Generes/Writers in the example? enter image description here

This is how I am adding the custom admin menu and I want each of them (Products, Promotions, Product Categories) to appear on the Appearance > Menu page on the same group "Online Shop". enter image description here

  • Provided the objects are set correctly when your CPT is registered, those tabs will be populated automatically as you add new pages/posts – dMcClintock Nov 9 '14 at 7:24
  • Hi dMcClintock, sorry I am new to to wordpress but if possible can you please give some sample on setting correctly the CPT so it will appear under e.g Genres or Writers. – dellboy Nov 9 '14 at 9:07
  • Can your copy the code you are using to create the custom post type into your question so I can see it? – dMcClintock Nov 9 '14 at 9:09
  • Sorry, I meant taxonomies. A basic example for registering them is here: codex.wordpress.org/Function_Reference/…. – dMcClintock Nov 9 '14 at 9:20
  • Ok, so using the code I have updated in my original post. How do I add the custom menus (Products, Promotions, and Product Categories)? The sample in the taxonomy section only allows me to add one group though. – dellboy Nov 9 '14 at 9:26
0

Using add_menu_page and add_submenu_page is generally used for adding pages to the dashboard to serve a specific purpose, such as accessing the options page for a plugin settings. Using them is unnecessary, however, if your intentions are to add/edit posts/tags/categories to a custom post type (CPT). When a CPT is correctly registered, with it's corresponding taxonomies, the Dashboard will display these menu options in the sidebar by default based on the conditions set in the $args when registering the cpt/tax.

Following is the code for creating a custom post type called "store_product", using a hierarchical organization structure for an associated taxonomy called "product_category". Note that hierarchical taxonomies are similar to categories - organized as a tree, with parent/child/sibling taxonomies, whereas non-hierarchial use a tag-like structure. You will want to replace all of the current code shown in your screenshot with the following.

(For future reference, the preferred means of providing your code is including it as a code sample, not an image - this makes it much easier for others to help you, and incidentally will increase your chances of getting help :)

/*
   Setup Custom Post Type "store_product"
   ========================================================================== */

function dm_create_online_store_post_type() {
    $labels = array(
        'name'                => 'Products',
        'singular_name'       => 'Product',
        'menu_name'           => 'Online Store',
        'parent_item_colon'   => 'Parent Product:',
        'all_items'           => 'All Products',
        'view_item'           => 'View Product',
        'add_new_item'        => 'Add New Product',
        'add_new'             => 'Add New',
        'edit_item'           => 'Edit Product',
        'update_item'         => 'Update Product',
        'search_items'        => 'Search Products',
        'not_found'           => 'Not found',
        'not_found_in_trash'  => 'Not found in Trash',
    );
    $rewrite = array(
        'slug'                => 'product', // http://your-domain.com/product/product-name/
        'with_front'          => true,
        'pages'               => true, // Allow pagination
        'feeds'               => true,
    );
    $args = array(
        'label'               => 'store_product',
        'description'         => 'Online Store',
        'labels'              => $labels, // This just pulls from the previous array of labels
        'supports'            => array( 'title', 'editor', 'thumbnail', ), // Fields available on the add/edit screen
        'taxonomies'          => array( 'product_category' ), // Referencing the taxonomy, created in next section, to replace the default categories
        'hierarchical'        => true, // If true, structure would be like pages. If false, it's like posts.
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true, // This tells it to show up in your admin menu
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'menu_position'       => 5, // Position in admin menu
        'menu_icon'           => 'http://', // Change this to the location of your icon
        'can_export'          => true,
        'has_archive'         => true,
        'exclude_from_search' => false,
        'publicly_queryable'  => true,
        'rewrite'             => $rewrite,
        'capability_type'     => 'post',
    );
    register_post_type( 'store_product', $args ); // Now that everything is setup, register it.
}
add_action( 'init', 'dm_create_online_store_post_type', 0 ); // Necessary to actually run the above function


/*
   Setup Custom Taxonomy "product_category" for use with above post type
   ========================================================================== */

function dm_create_online_store_product_categories() {
    $labels = array(
        'name'                       => 'Product Categories',
        'singular_name'              => 'Product Category',
        'menu_name'                  => 'Product Categories',
        'all_items'                  => 'All Categories',
        'parent_item'                => 'Parent Category',
        'parent_item_colon'          => 'Parent Category:',
        'new_item_name'              => 'New Category Name',
        'add_new_item'               => 'Add New Category',
        'edit_item'                  => 'Edit Category',
        'update_item'                => 'Update Category',
        'separate_items_with_commas' => 'Separate categories with commas',
        'search_items'               => 'Search categories',
        'add_or_remove_items'        => 'Add or remove categories',
        'choose_from_most_used'      => 'Choose from the most used categories',
        'not_found'                  => 'Not Found',
    );
    $rewrite = array(
        'slug'                       => 'product-category', // http://your-domain.com/product-category/product-category-name
        'with_front'                 => true,
        'hierarchical'               => true,
    );
    $args = array(
        'labels'                     => $labels,
        'hierarchical'               => true, // If true, they act like categories. If false, like tags.
        'public'                     => true,
        'show_ui'                    => true,
        'show_admin_column'          => true,
        'show_in_nav_menus'          => true,
        'show_tagcloud'              => true,
        'rewrite'                    => $rewrite,
    );
    register_taxonomy( 'product_category', array( 'store_product' ), $args ); // Register it to our post type
}
add_action( 'init', 'dm_create_online_store_product_categories', 0 ); // Necessary to actually run the above function

The result, as shown in the dashboard screen, appears as such:

Dashboard view of new Post Type

A look at Appearance / Menus will show "Products" and "Product Categories", just like it was showing "Genres/Authors" before (if you don't see it, open the "Screen Options" tab in the top right, and make sure they are checked).

To populate them, simply add a product category, and a product - assigning that product to the category, like so:

Add category to your custom taxonomy

Add product to your custom post type

Looking back at your menus screen in the dashboard, you should see both listed:

enter image description here

  • Thanks dMcClintock for the very detailed sample. However, I tried running the script on functions.php but even if I added items in the products and product categories I do not see these items being added in the Appearance Menu page but headers are there but without the content. Any thoughts? – dellboy Nov 9 '14 at 13:44
  • Nevermind, I found what was causing it. Thank you so much dMcClintock! – dellboy Nov 9 '14 at 14:01
  • For the purpose of future readers (and myself), was something in my answer causing the issue? If so, I'll want to edit my answer to fix it. Otherwise, I'm glad it worked for you. – dMcClintock Nov 9 '14 at 15:14
  • No not at all, your answer works like charm. The one causing the issue is my javascript which fails to load the interval animation in opening the accordion in the nav-menu page. Again, thank you so much dMcClintock – dellboy Nov 9 '14 at 16:01
0

How have you added this custom post type? Did you use a plugin or code it into your functions.php?

If you coded it, you can add 'show_in_nav_menus' => true, to your $args.

You can read about it here. http://codex.wordpress.org/Function_Reference/register_post_type

  • hi damienoneill2001, thanks for your response. I coded it because I am creating a theme out of this and I am using add_menu_page and add_submenu_page to add the custom menus. – dellboy Nov 9 '14 at 3:43
  • I have read the article and tried the sample as sample, I can see that it added an item block in the Appearance > Menu. So how do I add the content in there? Any thoughts? – dellboy Nov 9 '14 at 4:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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