post class output category and tag only

somehow this is worked.

$cat_html = get_the_category();
$tag_html = get_the_tags();
echo 'class="' . $cat_html[0]->slug . ' ' . $tag_html[0]->slug . '"';

I’m glad you found a solution, but slug is not the same as nice name, as in $cat_html[0]->name. That said, you’re actually better off using the slugs because names can have uppercase chars and spaces, which are not good as class attribute values. Just sayin’ 🙂

Yes, thank you. How to output tag nickname? $tag_html[0]->nicename doesn’t work.

name and slug properties are your only reasonable options by default. I encourage you to stay with slug, but do as you wish, it’s your site 🙂

There is no nice name or nickname field for tags unless it has been added by your theme or a plugin. When that is done, the value is usually saved in the term meta table. You’d need to know what key it’s saved under.



Source link