Skip to content
Advertisement

How to get all tags from WordPress page/post as a list in shortcode?

At the end of each page and every post, I would like to output the tags as a list in a shortcode.

Unfortunately, I do not know much about PHP, but someone who can understand will definitely be able to correct my mistake using the code below.

Thank you in advance!

JavaScript

Advertisement

Answer

The method needs to return a string to be able to print any markup.

“Shortcode functions should return the text that is to be used to replace the shortcode.” https://codex.wordpress.org/Function_Reference/add_shortcode

JavaScript

Edit: Removed check for is_page since get_the_tags will simply return empty if there aren’t any

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement