How to display all current post categories in a post

Hi there I tried to show some current post info via global block inside the a post.

To show and link a current category I’m using {{dc:archive:url}} and {{dc:archive:title}} but it will only display one category (the first one I guess). How can I display all current categories? Some posts might have two or three categories.

Thank you

Hi @ArtOfSpring,

You may create a shortcode that will display the list of categories assigned to a post then use that shortcode in the post to have the categories listed.

To do that, Please install and activate the child theme and login through FTP then edit the functions.php then add this code:

function display_post_categories( $atts ) {
	return '<span class="post-categories">' . get_the_category_list(', ') . '</span>';
}

add_shortcode( 'the_post_categories', 'display_post_categories' );

Then in the post, add the shortcode [the_post_categories]

Hope this helps.

1 Like

Thanks a lot!

You’re most welcome.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.