Display Custom Taxonomy Name As A Shortcode

Question

On my WordPress site I have created a custom taxonomy named “game” which lists different gaming titles. I want to be able to display the names of these titles on my posts using a shortcode.

Prior to creating a custom taxonomy, I was using WordPress’ default categories taxonomy, and had the following code (found on stack exchange) working well:

function shortcode_post_category () {
    $html = '';
    $categories = get_the_category();
    foreach( $categories as $category ){
        $html .= '<h2>' . strtoupper($category->name) . ' KEYBINDS</h2>';
    }
    return $html;
}
add_shortcode( 'category-keybinds', 'shortcode_post_category' );

From what I understand I need to change the get_the_categories to get_the_term(?) however with my very limited knowledge of php I cannot seem to get this to work on the new “game” taxonomy.

0
, , Tom 4 years 2020-05-23T12:10:27-05:00 0 Answers 85 views 0

Leave an answer

Browse
Browse