Site logo

Archived topic

PHP for generating post term tags

5 replies · Started by Antoinette on December 10, 2020

Viewing posts 1–6 of 6

Please can you give me the PHP snippet to generate a shortcode for generating post terms (tags and categories) to insert into templates using the Elements block?

Thanks!

Hi there,

you can do something like this:

add_shortcode( 'display_terms', function() {
    ob_start();
    echo '<div class="entry-meta">';
     	generate_do_post_meta_item( 'categories' );
	generate_do_post_meta_item( 'tags' );	
    echo '</div>';
    return ob_get_clean();
} );

This will create the [display_terms] shortcode

You wonderful person. That works like a dream, thank you.

You're welcome - very happy to be of help - and really happy to see the use of the Block Element :) In the future you will be able to do this without the need for shortcodes!

Amazing. It's super useful and intuative, muuuuuuch easier than cowboying my way through the more complicated functions.

Totally true - and it will get better over time. Glad to hear your enjoying these features

This archived topic is closed to new replies.