I want to share a wordpress post on twitter. I'm using this :

<a href="https://twitter.com/share?url=<?php the_permalink() ?>&text=<?php the_title() ?>&via=<?php the_author() ?>&hashtags=<?php the_tags('', '') ?>" ></a>

My problem is that the_tags() prints the tags inside the <a> tag. How can I use the_tags('', '') ( which separates the tags with comma as the hashtag needs to be ) for twitter hashtags ?

I would appreciate any solutions without the use of a plugin

1 Answer 1


get_the_tags() with a little bit of processing will do it:

$tags = get_the_tags();
$tag_list = wp_list_pluck($tags,'name');
$tag_list = implode(',',$tag_list);


  • then I should put <? echo $tags ?> in the URL ? Commented May 26, 2014 at 19:10
  • echo $tag_list; actually, but yes.
    – s_ha_dum
    Commented May 26, 2014 at 19:12
  • very nice thanks. it worked. but there is a problem that the php codes prints this : string 'Elearnica' (length=9) ( Elearnica is the post tag ) how can I stop printing it ? Commented May 26, 2014 at 19:21
  • The var_dump() is for debugging only. Remove it from your working code.
    – s_ha_dum
    Commented May 26, 2014 at 19:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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