Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Just add the_tags() to the shortcode:

function wpse_82190_tags(){

    return the_tags();
}
add_shortcode('tags', 'wpse_82190_tags');
share|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
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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