Add '#' beside each wordpress tag

馋奶兔 提交于 2020-01-05 04:18:05

问题


I'm trying to add hashtags beside my post tags in Wordpress.

With this code, it looks like : tag1, tag2, tag3

<?php the_tags( '<span class="meta-sep"> | </span><span class="tag-links">' . __( '', 'portfoliopress' ) . '</span>', ', ', '' ); ?>

But I'd like to change it to : #tag1, #tag2, #tag3

I tried to add # into this part

', ', ', '' ); ?>

but it gave me a fatal error. I don't know PHP, but it seems like a simple task. Am I looking in the wrong place?


回答1:


<?php the_tags( '#', ', #', '' ); ?>

EDIT: to add the # to the link text:

if( $tags = get_the_tags() ) {
    echo '<span class="meta-sep"> | </span>';
    foreach( $tags as $tag ) {
        $sep = ( $tag === end( $tags ) ) ? '' : ', ';
        echo '<a href="' . get_term_link( $tag, $tag->taxonomy ) . '">#' . $tag->name . '</a>' . $sep;
    }
}


来源:https://stackoverflow.com/questions/20705398/add-beside-each-wordpress-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!