WordPress allows you to organize posts using tags and categories, but sometimes you need more options. This is where custom taxonomies come in handy, allowing you to arrange content exactly how you want. For instance, a movie blog might use “Genres” or “Topics” to categorize posts. Once developed, you can easily display custom taxonomy terms on your website.
Displaying taxonomy terms in a sidebar widget enhances your website’s usability, making it easier for users to find content quickly. But how do you display taxonomy in a sidebar? This article outlines two simple methods—using a bit of code or a plugin. Even if you’re not a tech expert, you can follow these guidelines to showcase your custom taxonomy terms effectively.
In WordPress, taxonomies help organize and classify content. While the default taxonomies—tags and categories—serve most needs, they’re sometimes not enough. Custom taxonomies offer greater flexibility, allowing you to create labels based on your website’s specific content type or theme, enhancing site navigation and control.
Custom taxonomies can be attached to posts, pages, and custom post types, functioning much like tags or categories to speed up content searches and improve user experience.
Here are three straightforward techniques to showcase custom taxonomy keywords in your WordPress sidebar:
If you’re comfortable with programming, you can use a custom function to display terms anywhere on your site or in a widget.
Step 1: Register the Custom Taxonomy
You might have done this already, but if not, here’s an example code to create a new taxonomy called “Genre” for posts:
function create_custom_taxonomy() {
register_taxonomy(
'genre',
'post',
array(
'label' => 'Genres',
'rewrite' => array('slug' => 'genre'),
'hierarchical' => true,
)
);
}
add_action('init', 'create_custom_taxonomy');
Step 2: Display Custom Taxonomy Terms in the Sidebar Widget
Add the following code to your theme’s functions file or a custom plugin:
function display_genre_terms_widget() {
$terms = get_terms(array(
'taxonomy' => 'genre',
'hide_empty' => false,
));
if (!empty($terms) && !is_wp_error($terms)) {
echo '<ul>';
foreach ($terms as $term) {
$term_link = get_term_link($term);
echo '<li><a href="' . esc_url($term_link) . '">' . esc_html($term->name) . '</a></li>';
}
echo '</ul>';
}
}
function register_genre_widget() {
register_sidebar(array(
'name' => 'Custom Taxonomy Sidebar',
'id' => 'custom_taxonomy_sidebar',
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>',
));
}
add_action('widgets_init', 'register_genre_widget');
Use this function in your sidebar template:
if (is_active_sidebar('custom_taxonomy_sidebar')) {
display_genre_terms_widget();
}
For those who prefer not to code, using a plugin is an excellent option. Many plugins, like a taxonomy widget plugin, allow widgets to display custom taxonomies.
Recommended Plugin: “Custom Taxonomy Widget”
Steps to Use:
Your sidebar will now display the taxonomy terms. Most plugins offer display options like dropdown menus or showing post counts.
WordPress’s block-based widget editor allows for more flexible design.
Steps to Use:
Certain plugins display taxonomies using shortcodes. You can paste these directly into the widget block.
The output will appear plain unless styled. Custom CSS can enhance its appearance.
Sample CSS:
.widget ul {
list-style: none;
padding: 0;
}
.widget ul li {
padding: 5px 0;
}
.widget ul li a {
color: #0073aa;
text-decoration: none;
}
.widget ul li a:hover {
text-decoration: underline;
}
Add this CSS by going to Appearance > Customize > Additional CSS.
Displaying custom taxonomy terms in your WordPress sidebar improves user experience and site navigation. Whether you prefer coding, using plugins, or the block editor, there’s a method suitable for every skill level. Custom taxonomies allow users to find relevant posts by organizing content more efficiently. Including taxonomy terms in your sidebar acts as a great filter, increasing user engagement and enhancing SEO. Don’t forget to style your widgets with CSS for a polished look. By applying these simple techniques, your WordPress site will become more aesthetically pleasing and user-friendly.