最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

How to add a class to anchor tags using the get_the_tag_list(); function?

matteradmin8PV0评论
This question already has answers here: How do I change the output of get_the_tag_list()? (3 answers) Closed 6 years ago.

What's the easiest way to add a class to the anchor tag using the get_the_tag_list() function?

For example by adding;

if(get_the_tag_list()) {
echo get_the_tag_list('<ul><li>','</li><li>','</li></ul>');
}

Will return something like this;

<ul>
<li><a href="tag1">Tag 1</a></li>
<li><a href="tag2">Tag 2</a></li>
 ... 
</ul>

I just need something to add a custom class to the anchor. Thank you.

This question already has answers here: How do I change the output of get_the_tag_list()? (3 answers) Closed 6 years ago.

What's the easiest way to add a class to the anchor tag using the get_the_tag_list() function?

For example by adding;

if(get_the_tag_list()) {
echo get_the_tag_list('<ul><li>','</li><li>','</li></ul>');
}

Will return something like this;

<ul>
<li><a href="tag1">Tag 1</a></li>
<li><a href="tag2">Tag 2</a></li>
 ... 
</ul>

I just need something to add a custom class to the anchor. Thank you.

Share Improve this question asked Oct 29, 2018 at 20:26 Foxtrail815Foxtrail815 192 bronze badges 1
  • Check this wordpress.stackexchange/questions/32234/… – Michael Commented Oct 29, 2018 at 21:03
Add a comment  | 

1 Answer 1

Reset to default 1

I finally found the solution using a filter:

add_filter( "term_links-post_tag", 'add_tag_class');

function add_tag_class($links) {
return str_replace('<a href="', '<a class="myclass" href="', $links);
}
Post a comment

comment list (0)

  1. No comments so far