Display Taxonomy Inline in WordPress

In WordPress, taxonomies are an essential part of organizing and managing content. Categories, tags, and custom taxonomies help users find related content quickly, improving the navigation experience. However, the way taxonomies are displayed on your WordPress website can impact the overall user experience and aesthetics. A popular method is displaying taxonomy terms inline. This guide will provide a step-by-step process on how to display taxonomies inline in WordPress, along with practical tips, advanced techniques, and best practices to ensure an optimal implementation.

 

What Does “Display Taxonomy Inline” Mean in WordPress?

Displaying taxonomy inline refers to showing taxonomy terms, such as categories or tags, horizontally rather than vertically. This presentation style saves space and enhances the design, making your WordPress site appear cleaner and more organized. Inline taxonomy displays are often used in blog posts, product pages, and meta-data sections to provide quick access to related terms.

Example:

  • Vertical display:

    • WordPress
    • Development
    • Tutorials
  • Inline display:
    WordPress | Development | Tutorials

In this context, inline formatting can be applied to various taxonomies (categories, tags, or custom taxonomies) across your WordPress site.

Why Display Taxonomy Inline in WordPress?

Before diving into the technical details, it’s crucial to understand why displaying taxonomy inline is beneficial for your website.

  1. Improved Aesthetics: Inline taxonomies help declutter the page, contributing to a more professional and modern look. They are perfect for minimalist and clean designs where you want to save vertical space and give the page a well-organized feel.

  2. Better User Experience (UX): Visitors can quickly identify and click on relevant taxonomy terms, leading to better navigation and faster content discovery. Inline formatting also makes it easier for users to understand the relationships between content without overwhelming them with excessive links or clutter.

  3. SEO Benefits: While taxonomy inline displays are mainly a design choice, they can indirectly benefit SEO by improving the internal linking structure. This boosts the search engine crawlability and relevancy of your content.

  4. Efficient Use of Space: For content-heavy sites, especially those with a lot of taxonomies, displaying them inline allows you to use space more efficiently. It also reduces the need for excessive scrolling, providing a seamless user experience.

How to Display Taxonomy Inline in WordPress

There are several ways to display taxonomy inline in WordPress. Whether you’re a beginner or an advanced developer, you can achieve this using various methods, including custom code or plugins. Let’s go through each approach in detail.

1. Using PHP to Display Taxonomy Inline

WordPress provides functions like get_the_terms() and the_terms() that allow developers to retrieve and display taxonomy terms. You can customize how taxonomies appear on the front-end using PHP.

Step-by-Step Guide:

  1. Access the Template File: The first step is to locate the template file where you want to display the taxonomies. This could be single.php, content.php, or any other template file based on your theme.

  2. Use get_the_terms() Function: The get_the_terms() function retrieves taxonomy terms for a specific post or page. You can use this function to fetch the taxonomy terms and display them inline.

    PHP Code:

    php
    <?php $terms = get_the_terms(get_the_ID(), ‘category’); // Replace ‘category’ with your taxonomy name if ($terms && !is_wp_error($terms)) { $term_list = array(); foreach ($terms as $term) { $term_list[] = ‘<a href=”‘ . get_term_link($term) . ‘”>’ . $term->name . ‘</a>’; } echo implode(‘ | ‘, $term_list); // Separate terms with ‘ | ‘ } ?>

    Explanation:

    • This code retrieves the terms assigned to the current post for the specified taxonomy (e.g., category or custom taxonomy).
    • The terms are then looped through and displayed as links, separated by a pipe (|).

2. Styling Taxonomy Inline with CSS

Once the taxonomy terms are retrieved and displayed using PHP, you can use CSS to ensure the terms appear inline, making them look visually appealing.

CSS Code Example:

css
.inline-taxonomies a { display: inline-block; margin-right: 10px; text-decoration: none; color: #0073aa; } .inline-taxonomies a:hover { color: #005177; }

Explanation:

  • display: inline-block; ensures that the taxonomy terms are displayed in a horizontal line.
  • margin-right: 10px; adds spacing between the terms.
  • You can customize the hover effect and text color as per your theme’s style.

3. Using WordPress Plugins to Display Taxonomy Inline

If you are not comfortable with coding, there are several plugins available that can help you display taxonomies inline. Here are some of the most popular options:

  1. TaxoPress: TaxoPress allows you to manage and display taxonomies on your WordPress site easily. With the plugin, you can customize how taxonomies appear, including displaying them inline.

  2. WP Term Images: WP Term Images allows you to add images to your taxonomies. With a bit of customization, you can display these images inline alongside the taxonomy terms.

  3. ACF (Advanced Custom Fields): ACF is a versatile plugin that lets you customize taxonomies and display them inline using custom fields. You can create custom taxonomy fields, and then use PHP and CSS to display them inline.

  4. Custom Post Type UI (CPT UI): Custom Post Type UI is a plugin designed for creating custom post types and taxonomies. If you’re working with custom taxonomies, this plugin allows for easy integration and display.

Advanced Techniques for Displaying Taxonomy Inline

1. Displaying Multiple Taxonomies Inline

Sometimes, you might want to display terms from multiple taxonomies on the same post. For instance, you may want to display both the categories and tags of a post inline.

Code Example:

php
<?php $taxonomies = array(‘category’, ‘post_tag’); // Add the taxonomy names you want to display foreach ($taxonomies as $taxonomy) { $terms = get_the_terms(get_the_ID(), $taxonomy); if ($terms && !is_wp_error($terms)) { $term_list = array(); foreach ($terms as $term) { $term_list[] = ‘<a href=”‘ . get_term_link($term) . ‘”>’ . $term->name . ‘</a>’; } echo ‘<div class=”inline-taxonomies”>’ . implode(‘ | ‘, $term_list) . ‘</div>’; } } ?>

2. Display Taxonomy Terms with Icons

You can enhance the inline taxonomy display by adding icons. For example, you might want to display a small icon next to each category or tag. This can be achieved with a combination of PHP and an icon library like Font Awesome.

Example with Font Awesome:

php
<?php $terms = get_the_terms(get_the_ID(), ‘category’); if ($terms && !is_wp_error($terms)) { foreach ($terms as $term) { echo ‘<a href=”‘ . get_term_link($term) . ‘”><i class=”fas fa-tag”></i> ‘ . $term->name . ‘</a> | ‘; } } ?>

 

Best Practices for Displaying Taxonomy Inline

  1. Optimize for Performance: If you are displaying a large number of taxonomy terms, make sure your queries are efficient. Consider caching results or limiting the number of terms displayed to avoid performance issues.

  2. Use Clear Separators: When displaying taxonomy terms inline, use clear separators like a pipe (|) or comma (,) to distinguish terms from one another. Avoid excessive decoration that could make the display cluttered.

  3. Responsive Design: Ensure your inline taxonomies are responsive, meaning they should look good on both desktop and mobile screens. Use media queries in CSS to adjust the inline display for smaller screens.

  4. Ensure Accessibility: Make sure that your inline taxonomies are accessible to all users, including those using screen readers. Use appropriate HTML semantics and avoid relying solely on visual styling.

Conclusion

Displaying taxonomy inline in WordPress is an effective way to enhance the design and user experience of your website. Whether you’re using custom code or a plugin, the inline display of taxonomies helps create a more organized and visually appealing layout. It can also improve SEO by contributing to better internal linking.

With the methods and best practices outlined in this guide, you can easily implement inline taxonomy displays in your WordPress site and tailor them to suit your needs. Whether you’re working with categories, tags, or custom taxonomies, the flexibility of WordPress allows you to present taxonomy terms in a way that enhances both usability and design.


Interesting Reads:

What is Group Block in Gutenberg WordPress

What Are WordPress Hooks: A Tool or Feature

10 Best WordPress CDN Plugins for Images

Leave a Reply

Your email address will not be published. Required fields are marked *