How do I get the_tags() to output each tag so that it comes assigned with a unique class selector? So for example: the_tags() currently outputs something like this:
<a href="http://myblog.com/tag/kittens" rel="tag">kittens</a>
However, I'd like to output something like this:
<a href="http://myblog.com/tag/kittens" rel="tag" class="tag-kittens">kittens</a>
Is it possible to do this? If so, how? Thanks!
Because body classes are theme specific, you would need to add the following code to your theme's functions. php file. add_filter( 'body_class' , 'my_class_names' ); The above code will add a class “wpb-class” to the body tag on every page on your website.
Upon activation, you need to visit Appearance » Widgets page and add 'Tag Cloud (Simple Tags)' widget to the sidebar. The widget will expand, and you will be able to see its settings. Here you can select the number of tags you want to display, font sizes, colors, etc.
WordPress tags is one of the tools you can use to group your posts, based on similar details. Usually, tags are located under a post or in the sidebar. When a visitor clicks a particular tag, WordPress will open an archive page (tag page) – indexing all the posts and custom post types that have the same tags.
Also you can overload working of get_the_tags();
function.
Just add next code to your functions.php
theme file:
// add custom class to tag
function add_class_the_tags($html){
$postid = get_the_ID();
$html = str_replace('<a','<a class="class-name"',$html);
return $html;
}
add_filter('the_tags','add_class_the_tags');
this code from www.lawturn.com
/* SlSlib tags add class */
<?php if(has_tag()) : ?>
<?php
$tags = get_the_tags(get_the_ID());
foreach($tags as $tag){
echo '<a href="'.get_tag_link($tag->term_id).'" rel="tag" class="tag-'.$tag->name.'">'.$tag->name.'</a>';
} ?>
<?php endif; ?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With