WordPressでTwitterのシェアボタンをプラグイン等を使わずに実装するとき、記事に属するタグをツイートにハッシュタグとして含ませる場合、get_the_tag
を使って下記のコードのような感じで実現できます。
<?php $tags = get_the_tags(); $tag_list = wp_list_pluck($tags,'name'); $tag_list = implode(',',$tag_list); ?> <a href="https://twitter.com/share?url=<?php echo urlencode(get_permalink()); ?>&text=<?php echo urlencode(the_title('','',0));?>&hashtags=<?php echo $tag_list; ?>">text or image</a>
上記のコードはタグ名を出力するもので、下記のコードはスラッグ名を出力するものになります。
<?php $tags = get_the_tags(); $tag_list = wp_list_pluck($tags,'slug'); $tag_list = implode(',',$tag_list); ?> <a href="https://twitter.com/share?url=<?php echo urlencode(get_permalink()); ?>&text=<?php echo urlencode(the_title('','',0));?>&hashtags=<?php echo $tag_list; ?>">text or image</a>
参照: WordPress tags as twitter sharer URL hastags – WordPress Development Stack Exchange