How to Display Custom Taxonomy With Genesis Framework Shortcode

Besides hooks, Genesis Framework has lots of shortcodes to help you customize your child theme. Before this, we’ve published a tutorial on creating your first custom post type and custom taxonomy and today, we’ll show how easy it is to display the custom taxonomy on your site.

Using [post_terms] Shortcode

If you refer to Genesis shortcode reference page, you’ll notice a less-known [post_terms] shortcode. To display any custom taxonomy, we’ll be using this shortcode and place it on entry meta. The shortcode accepts 4 parameters: sep - This will be the separator for the post terms list. The default is comma. before - Text to be displayed before the post terms list. The default is “Filed Under: “, same as category. after - Text to be displayed after the post terms list. taxonomy - Specify which taxonomy to be displayed. This is the most important parameter need to be specified. The default value is category.

Displaying Custom Taxonomy in Entry Meta (Footer)

To display the custom taxonomy in entry meta (footer), we’ll use genesis_post_meta filter. Here’s a working code that can be placed on your child theme functions.php file:

1 2 3 4 5 6 7 8 9
<?php
//* Display custom tax in the entry footer (Genesis Framework - HTML5)
add_filter( 'genesis_post_meta', 'afn_display_custom_tax' );
function afn_display_custom_tax($post_meta) {
$post_meta = '[post_terms taxonomy="type" before="Type: "]';
return $post_meta;
}
view raw functions.php hosted with ❤ by GitHub

In this example, ‘Type’ is my custom taxonomy. Please note that the code above will overwrite the current entry meta and therefore it will remove post categories and tags.

Conditionally Display Custom Taxonomy on Custom Post Type

To conditionally display custom taxonomy anywhere on your site, we need to use conditional tags. In this example, we are using is_singular and is_post_type_archive tags. Here’s a tested and working code that can be placed on your child theme function.php file:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<?php
//* Conditionally display custom tax in entry footer (Genesis Framework - HTML5)
function afn_display_conditionals() {
if ( is_singular( 'portfolio' ) || is_post_type_archive( 'portfolio' ) ) {
add_filter('genesis_post_meta', 'afn_display_custom_tax');
}
}
function afn_display_custom_tax($post_meta) {
$post_meta = '[post_terms taxonomy="type" before="Type: "]';
return $post_meta;
}
add_action('wp', 'afn_display_conditionals');
view raw functions.php hosted with ❤ by GitHub

What the code will do is basically to only display the custom taxonomy on single page of Portfolio post type and on the archive page of Portfolio post type.

Genesis Feature Post Widget

The best thing about Genesis shortcodes is they can also be used on Genesis Featured Post widget. Therefore, if you’ve custom taxonomy and would like to display it, you may also use the [post_terms] shortcode. [post_terms taxonomy="type" before="Type: "] Simply replace “type” and “Type: ” with the name of your custom taxonomy. We hope this tutorial helped you to easily display the custom taxonomy on your theme. For more info about Gensis Framework shortcode, I highly suggest you check out the Shortcode Reference page on StudioPress site.

Comments

  1. Julia says

    Thank you!! I’ve tried several variations of this from loads of different tutorials, but this is the only one that actually worked. You’re a star!

    • Editor says

      I’ve provided an example above. In the widget settings panel, you may insert the shortcode in the “Show Post Info” field.

  2. Sidra says

    How to show all the data in a taxonomy using [post_terms]?
    I mean I want to show all events [this my custom created taxonomy] in a post from a to z. How?

    • Editor says

      The shortcode can only be used inside a loop and it’s intended to display the list of taxonomy/taxonomies that the post belongs to.

  3. Floyd says

    Thank you very much, very helpful. The sad thing is that I had to use Duckduckgo to find your tutorial. I have been trying for maybe 3 days to display my custom taxonomies. I was able to modify your code to display my numerous custom taxonomies.

Leave a Reply

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