it feel like this should be easy. I want to add the post tags inside the body of some posts. I was thinking that creating a shortcode may be the answer. I came across these 2 pieces of code:

To display the tags...

<p><?php the_tags(); ?></p>

To create a shortcode...

function show_current_year(){
    return date('Y');
add_shortcode('show_current_year', 'show_current_year');

I can't combine the 2! Can anyone help? The only other solution would be to insert the php directly in the post but I think I'd need a plug-in to do that and I'm a bit wary.


Just add the_tags() to the shortcode:

function wpse_82190_tags(){

    return the_tags();
add_shortcode('tags', 'wpse_82190_tags');
| improve this answer | |
  • Thank you that works a treat - I expected it to position the tags where the shortcode is placed rather than at the top of the post but I'll have a play and see what's going on. – Paul Brown Jan 18 '13 at 18:49
  • 1
    get_the_tag_list() will return the result where the shortcode is; codex.wordpress.org/Function_Reference/get_the_tag_list – Michael Jan 18 '13 at 22:16
  • Hi Michael thank you - I'll have a look at that. Sounds like it could result in precisely what I'm after. As it is the existing code is implemented and is fine but being a perfectionist control of positioning would be a dream! – Paul Brown Jan 19 '13 at 16:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.