• Sweet Solutions
  • About
  • Services
  • Design Packages
  • Get Started
  • Portfolio
    • Featured Projects
  • Testimonials
  • Blog
  • Contact

Sweet Solutions

Web design with flair

My Custom Taxonomy for Recipe Tags

Thursday, November 19, 2015Leave a Comment

Tag cloud
Tag cloud at Our Empty Nest

Let’s say you have a blog, and on that blog you post recipes. Each time you post a recipe you file it under one or more tags—salads, soups, desserts, chicken, fish, Italian, Mexican, pasta, or another tag that’s appropriate.

Whenever you post anything on your blog, whether it’s a recipe or not, you tag it. Tags are a useful way of grouping related posts together. Readers can quickly tell what the post is about, or they can click on the tag to see a list of related posts they might be interested in reading.

Now let’s say, you want only the tags for your recipes to appear in your sidebar as I did at Our Empty Nest. The default tag cloud in the WordPress widget area will pick up tags for all of your posts, not just for recipes.

What you need is a custom taxonomy especially for “recipes.”

Here’s how to do it

IMPORTANT: In all cases, if you change the name of the taxonomy from recipes to something else, be sure to change every instance of “recipes” in the code.

  1. Create the custom taxonomy by adding the following code to your functions.php:
    /** Register custom taxonomy */
    add_action( 'init', 'register_taxonomy_recipes' );
    function register_taxonomy_recipes() {
        $labels = array(
        'name' => _x( 'Recipes', 'recipes' ),
        'singular_name' => _x( 'Recipes', 'recipes' ),
        'search_items' => _x( 'Search Recipes', 'recipes' ),
        'popular_items' => _x( 'Popular Recipes', 'recipes' ),
        'all_items' => _x( 'All Recipes', 'recipes' ),
        'parent_item' => _x( 'Parent Recipes', 'recipes' ),
        'parent_item_colon' => _x( 'Parent Recipes:', 'recipes' ),
        'edit_item' => _x( 'Edit Recipes', 'recipes' ),
        'update_item' => _x( 'Update Recipes', 'recipes' ),
        'add_new_item' => _x( 'Add New Recipes', 'recipes' ),
        'new_item_name' => _x( 'New Recipes', 'recipes' ),
        'separate_items_with_commas' => _x( 'Separate recipes with commas', 'recipes' ),
        'add_or_remove_items' => _x( 'Add or remove recipes', 'recipes' ),
        'choose_from_most_used' => _x( 'Choose from most used recipes', 'recipes' ),
        'menu_name' => _x( 'Recipes', 'recipes' ),
        );
        $args = array(
        'labels' => $labels,
        'public' => true,
        'show_in_nav_menus' => true,
        'show_ui' => true,
        'show_tagcloud' => true,
        'show_admin_column' => true,
        'hierarchical' => true,
        'rewrite' => true,
        'query_var' => true
        );
        register_taxonomy( 'recipes', array('post'), $args );
    }
  2. To have the new custom taxonomy appear at the bottom of your posts, add the following code to your functions.php:
    /** Customize post meta function */
    add_filter( 'genesis_post_meta', 'post_meta_filter' );
    function post_meta_filter($post_meta) {
        if ( !is_page() ) {
        $post_meta = '[post_tags before="Filed under "][post_terms taxonomy="recipes" before="Filed under "]';
        return $post_meta;
        }
    }
  3. The default number of tags in a tag cloud is 45. If you have more than 45 tags and want all of the tags to appear, add the following code to functions.php:
    /** Change number of tags in tag cloud */
    add_filter( 'widget_tag_cloud_args', 'custom_tag_cloud_widget' );
    function custom_tag_cloud_widget($args) {
        $args['number'] = 0; //adding a 0 will display all tags
        $args['exclude'] = array(); //exclude or include tags by ID
        return $args;
    }
  4. Go to Settings >> Permalinks and SAVE.

That’s it. Your new custom taxonomy will be listed in your Dashboard menu on the left under Posts. When you write a new post, you’ll find Tags and Recipes on the right side of the edit screen. To add a tag to the new taxonomy, click Add New Recipes. If the tag you want is already listed, just check the box. On existing recipes, delete tags and create new ones using the new custom taxonomy. If you want to use both tags and the new taxonomy, you’ll have to further customize the meta function.

Any questions, just ask.

Similar posts you might like

My Current-Menu-Item
I'm not especially fond of breadcrumbs. I have nothing against them personally and have no problem w...
PHP 5 is dead . . . Long live PHP 7
PHP 5 is dead. It died on December 31, 2018. At the end of this month, security patches and updates ...
Share on Facebook
Facebook
Tweet about this on Twitter
Twitter
Pin on Pinterest
Pinterest
Share on LinkedIn
Linkedin
Email this to someone
email

Filed under how to do it, taxonomies

cool • creative • inspiring Sweet Solutions web design ♥ with flair

Let's Get Started

Leave a Comment Cancel reply

Time limit is exhausted. Please reload CAPTCHA.

strawberries

What I Write About

added flair favicons Google doodles hosting how to do it marketing menus mobile responsiveness my other life PHP Sweet Solutions taxonomies the cloud UX web design WordPress
Archives

Let’s Connect

Tweets by @sweetsolutions1

Sweet Solutions

Location

Patricia Petro
Sweet Solutions
Findlay, OH USA

Email: patpetro@msn.com
somesweetsolutions.com

Calendar

We are currently booked 1-2 months
in advance on projects.
Contact us to get in queue.

Contact Form

Let’s Connect

  • Facebook
  • LinkedIn
  • Twitter

Sweet Solutions is featured at National WebDesigners-Directory, Best Web Design Agencies, and DesignFirms.

ESTd 2002 • Copyright © 2021 Patricia Petro • Created with ♥ in WordPress and Genesis.

PRIVACY POLICY • TERMS OF SERVICE • FAQs • LOGIN

strawberries and cream

»
«