WPBeginner

Beginner's Guide for WordPress

  • Blog
    • Beginners Guide
    • News
    • Opinion
    • Showcase
    • Themes
    • Tutorials
    • WordPress Plugins
  • Start Here
    • How to Start a Blog
    • Create a Website
    • Start an Online Store
    • Best Website Builder
    • Email Marketing
    • WordPress Hosting
    • Business Name Ideas
  • Deals
    • Bluehost Coupon
    • SiteGround Coupon
    • WP Engine Coupon
    • HostGator Coupon
    • Domain.com Coupon
    • Constant Contact
    • View All Deals »
  • Glossary
  • Videos
  • Products
X
☰
Beginner's Guide for WordPress / Start your WordPress Blog in minutes
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

WPBeginner» Blog» Plugins» How to Display Custom Taxonomy Terms in WordPress Sidebar Widgets

How to Display Custom Taxonomy Terms in WordPress Sidebar Widgets

Last updated on April 15th, 2013 by Editorial Staff
51 Shares
Share
Tweet
Share
Pin
Free WordPress Video Tutorials on YouTube by WPBeginner
How to Display Custom Taxonomy Terms in WordPress Sidebar Widgets

WordPress has come a long way from being a simple blogging platform. With additions of custom post types and custom taxonomies, it is being used as a true content management system (CMS). In response from our article on how to create custom taxonomies in WordPress, some of our readers asked us how to display custom taxonomy terms in sidebar widgets. In this article we will show you how to display custom taxonomy terms in WordPress sidebar widgets.

We will show you how to display custom taxonomy terms in sidebar widgets using two different methods. The first method is by installing a plugin which is simpler and easier. We recommend using this method for majority of our audience. The second method involves creating your own shortcode. This method is for those who like to know how things work and have more control over the output.

Adding Custom Taxonomy Terms in a Widget (Plugin)

To display custom taxonomy terms in sidebar or other widget areas using a plugin, the first thing you need to do is install and activate Custom Taxonomies Menu Widget plugin. Upon activation, it adds a custom taxonomies menu widget under Appearance » Widgets. Drag and drop the widget to your sidebar. The widget configuration options allow you to choose the taxonomies you want to display or exclude. It also allows you to exclude terms inside a taxonomy.

Showing Custom Taxonomies in Sidebar using Widget

Adding Custom Taxonomy Terms with Shortcode

Custom Taxonomies Menu Widget plugin allows you to easily display terms from any custom taxonomy, without worrying about the code. However some users would want to learn how to do it manually, so that they could have more control on how terms for their custom taxonomy appears in their widgets. Furthermore, using the shortcode method allows you to display taxonomy terms within your post content should you need to.

First we need to create a shortcode that displays a list of terms and accepts parameters. The only parameter we need is the name of the taxonomy. Add this code in a site-specific plugin:


// First we create a function
function list_terms_custom_taxonomy( $atts ) {

// Inside the function we extract custom taxonomy parameter of our shortcode

	extract( shortcode_atts( array(
		'custom_taxonomy' => '',
	), $atts ) );

// arguments for function wp_list_categories
$args = array( 
taxonomy => $custom_taxonomy,
title_li => ''
);

// We wrap it in unordered list 
echo '<ul>'; 
echo wp_list_categories($args);
echo '</ul>';
}

// Add a shortcode that executes our function
add_shortcode( 'ct_terms', 'list_terms_custom_taxonomy' );

//Allow Text widgets to execute shortcodes

add_filter('widget_text', 'do_shortcode');

The code above creates a shortcode ct_terms that requires one parameter custom_taxonomy. To use this shortcode drag and drop a Text widget into your sidebar. Add this shortcode in your Widget and save.

[ct_terms custom_taxonomy=customtaxonomyname]

Replace customtaxonomyname with the name of the taxonomy you want to list.

We hope that you find this article useful in displaying custom taxonomy terms in your sidebar or other widget area. Let us know how you prefer to list terms of a custom taxonomy in the comments below.

51 Shares
Share
Tweet
Share
Pin
Popular on WPBeginner Right Now!
  • How to Start Your Own Podcast (Step by Step)

    How to Start Your Own Podcast (Step by Step)

  • Checklist

    Checklist: 15 Things You MUST DO Before Changing WordPress Themes

  • How to Properly Move Your Blog from WordPress.com to WordPress.org

  • Revealed: Why Building an Email List is so Important Today (6 Reasons)

    Revealed: Why Building an Email List is so Important Today (6 Reasons)

About the Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Trusted by over 1.3 million readers worldwide.

The Ultimate WordPress Toolkit

18 Comments

Leave a Reply
  1. Jared says:
    Jul 8, 2020 at 7:04 pm

    “This plugin has been closed as of November 25, 2018 and is not available for download. Reason: Guideline Violation.”

    Reply
    • WPBeginner Support says:
      Jul 9, 2020 at 9:04 am

      Thank you for letting us know, we will certainly take a look and update this article when we are able.

      Reply
  2. Mario says:
    Jun 19, 2019 at 2:50 pm

    I am getting this warning in my site:

    Warning: Use of undefined constant taxonomy – assumed ‘taxonomy’ (this will throw an Error in a future version of PHP) in…

    Reply
    • WPBeginner Support says:
      Jun 20, 2019 at 10:09 am

      It would depend on where that error message is being generated from. If the error says it is from wp-content/plugins/plugin name then you would want to reach out to that plugin’s support and they should be able to assist.

      Reply
  3. Antonio says:
    Apr 21, 2019 at 3:47 am

    Hi, the code give me this warning:

    Warning: Use of undefined constant taxonomy – assumed ‘taxonomy’ (this will throw an Error in a future version of PHP) in /home/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(361) : eval()’d code on line 12

    How can I fix it?
    Thanks

    Reply
    • WPBeginner Support says:
      Apr 22, 2019 at 1:53 pm

      on line 12 of the code, you would surround the word taxonomy with single quotes (‘ ‘) to remove that error :)

      Reply
  4. Nicole says:
    May 12, 2017 at 2:53 pm

    Hello, trying to apply this from within a post. I want it to list the custom taxonomies I have associated the post to and this is not working. How could I do this? Thanks!

    Reply
    • Dennis says:
      Oct 7, 2017 at 3:13 pm

      Yea I’m currently scouring the web trying to figure this out myself. Did you ever get a solid answer to this? It seems like it should be such a basic need

      Reply
  5. Hernan says:
    Feb 11, 2017 at 11:02 am

    Hi.
    Do you know how to put it so that it counts the posts of each “slug” of the custom taxonomy in the shortcode?

    Reply
  6. Muhammad Mobeen says:
    Jul 10, 2016 at 7:49 am

    Hi WPbeginner,

    Thanks for the code. It works. BUT I’m using it to output the taxonomies into the posts and list structure doesn’t display well (goes to the top of the post).

    Please guide me how to output the taxonomies in a span instead of a list.

    Reply
    • Deb S says:
      Nov 16, 2016 at 5:15 pm

      I had the same problem and had to modify the code somewhat.

      add ‘echo’=>false to your args

      $args = array(
      taxonomy => $custom_taxonomy,
      title_li => ”,
      ‘echo’ => false,
      );

      and then “return” the value instead of echoing it.

      $widgettext = ” . wp_list_categories($args) . ”;
      return $widgettext;

      and then the list displays inside the widget box.

      Reply
  7. deuts says:
    Jun 13, 2016 at 5:16 am

    What if I want to display a “linked” top 10 used terms of my custom taxonomy in a period of time (e.g. the last 30 or 90 days)?

    Reply
  8. siva says:
    Oct 26, 2015 at 7:41 am

    Hi Team

    Which php file, i want save code. please tell me

    Reply
  9. Chris says:
    Apr 11, 2014 at 1:16 pm

    Thank you!

    Saved me loads of time…..

    Reply
  10. Julie says:
    Jan 14, 2014 at 4:14 pm

    Finally! An article that works. I have tried all different approaches, but yours is simple and functions. I styled the list so it mimicked the look of the theme sidebar links. Thanks for the article!!

    Reply
  11. Nitin says:
    Oct 25, 2013 at 2:46 am

    Thanks for tutorial. My custom taxonomies are displaying. But the problom is my list is not in proper hierarchy. Child list is not displaying as a child. All data is displaying in a single unordered list. Second thing i want to give class to my parent list like and child also. How it can be possible.

    Reply
  12. Aniket says:
    Sep 18, 2013 at 1:38 am

    Hi,
    i would like to add selected taxonomies on my sidebar. I have installed the plugin and it works fine. But i would like to know/learn, is there a way to add selected taxonomies using the code? Like there could be a exclude or include feature where in i could manually add the id’s of the taxonomy that i would want to display or not. Thanks.

    Reply
  13. jas says:
    Jun 24, 2013 at 3:47 am

    very helpful post but i am facing one problem with this,
    i am using Custom Taxonomies Menu Widget and able to show a custom taxonomy in sidebar but when i click on the category link of custom taxonomy than page shows that No posts found.

    is there any problem in archive page????

    please help.

    Reply

Leave a Reply Cancel reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

Over 1,320,000+ Readers

Get fresh content from WPBeginner

Featured WordPress Plugin
All in One SEO logo
All in One SEO
Improve website SEO rankings with AIOSEO plugin. Learn More »
How to Start a Blog How to Start a Blog
I need help with ...
Starting a
Blog
WordPress
Performance
WordPress
Security
WordPress
SEO
WordPress
Errors
Building an
Online Store
Useful WordPress Guides
    • 7 Best WordPress Backup Plugins Compared (Pros and Cons)
    • How to Fix the Error Establishing a Database Connection in WordPress
    • Why You Need a CDN for your WordPress Blog? [Infographic]
    • 30 Legit Ways to Make Money Online Blogging with WordPress
    • Self Hosted WordPress.org vs. Free WordPress.com [Infograph]
    • Free Recording: WordPress Workshop for Beginners
    • 24 Must Have WordPress Plugins for Business Websites
    • How to Properly Move Your Blog from WordPress.com to WordPress.org
    • 5 Best Contact Form Plugins for WordPress Compared
    • Which is the Best WordPress Popup Plugin? (Comparison)
    • Best WooCommerce Hosting in 2020 (Comparison)
    • How to Fix the Internal Server Error in WordPress
    • How to Install WordPress - Complete WordPress Installation Tutorial
    • Why You Should Start Building an Email List Right Away
    • How to Properly Move WordPress to a New Domain Without Losing SEO
    • How to Choose the Best WordPress Hosting for Your Website
    • How to Choose the Best Blogging Platform (Comparison)
    • WordPress Tutorials - 200+ Step by Step WordPress Tutorials
    • 5 Best WordPress Ecommerce Plugins Compared
    • 5 Best WordPress Membership Plugins (Compared)
    • 7 Best Email Marketing Services for Small Business (2020)
    • How to Choose the Best Domain Registrar (Compared)
    • The Truth About Shared WordPress Web Hosting
    • When Do You Really Need Managed WordPress Hosting?
    • 5 Best Drag and Drop WordPress Page Builders Compared
    • How to Switch from Blogger to WordPress without Losing Google Rankings
    • How to Properly Switch From Wix to WordPress (Step by Step)
    • How to Properly Move from Weebly to WordPress (Step by Step)
    • Do You Really Need a VPS? Best WordPress VPS Hosting Compared
    • How to Properly Move from Squarespace to WordPress
    • How to Register a Domain Name (+ tip to get it for FREE)
    • HostGator Review - An Honest Look at Speed & Uptime (2020)
    • SiteGround Reviews from 4196 Users & Our Experts (2020)
    • Bluehost Review from Real Users + Performance Stats (2020)
    • How Much Does It Really Cost to Build a WordPress Website?
    • How to Create an Email Newsletter the RIGHT WAY (Step by Step)
    • Free Business Name Generator (A.I Powered)
    • How to Create a Free Business Email Address in 5 Minutes (Step by Step)
    • How to Install Google Analytics in WordPress for Beginners
    • How to Move WordPress to a New Host or Server With No Downtime
    • Why is WordPress Free? What are the Costs? What is the Catch?
    • How to Make a Website in 2020 – Step by Step Guide
Deals & Coupons (view all)
DesignEvo
DesignEvo Coupon
Get 25% OFF on DesignEvo premium logo making service.
AliDropship Coupon Code
AliDropship Coupon
Get 15% off on AliDropship WordPress and WooCommerce dropshipping plugin.
Featured In
About WPBeginner®

WPBeginner is a free WordPress resource site for Beginners. WPBeginner was founded in July 2009 by Syed Balkhi. The main goal of this site is to provide quality tips, tricks, hacks, and other WordPress resources that allows WordPress beginners to improve their site(s).
Join our team: We are Hiring!

Site Links
  • About Us
  • Contact Us
  • FTC Disclosure
  • Privacy Policy
  • Terms of Service
  • Free Blog Setup
  • Free Business Tools
Our Sites
  • OptinMonster
  • MonsterInsights
  • WPForms
  • SeedProd
  • Nameboy
  • RafflePress
  • Smash Balloon

Copyright © 2009 - 2021 WPBeginner LLC. All Rights Reserved. WPBeginner® is a registered trademark.

Managed by Awesome Motive | WordPress hosting by SiteGround | WordPress CDN by MaxCDN | WordPress Security by Sucuri.