• Resolved Fawzi

    (@fauzurrahman15)


    is there a way so post_class() prints category nicename and tag nicename only?

    • This topic was modified 3 years, 9 months ago by Fawzi.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Fawzi

    (@fauzurrahman15)

    somehow this is worked.

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

    (@bcworkz)

    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’ ??

    Thread Starter Fawzi

    (@fauzurrahman15)

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

    Moderator bcworkz

    (@bcworkz)

    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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘post class output category and tag only’ is closed to new replies.