• Resolved Tonis_troubles

    (@tonis_troubles)


    Hi AJ,

    I am wondering how to show the added taxonomies in the body class. I need to be able to call by taxonomy for styling.

    Thx!
    Tonny

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Tonis_troubles

    (@tonis_troubles)

    Found it! I added this so functions

    //add taxonomy to body class
    function add_taxonomy_to_single( $classes ) {
    if ( is_single() ) {
    global $post;
    $my_terms = get_the_terms( $post->ID, ‘soort_expertise’ );
    if ( $my_terms && ! is_wp_error( $my_terms ) ) {
    $classes[] = $my_terms[0]->slug;
    }
    return $classes;
    }
    }
    add_filter( ‘body_class’, ‘add_taxonomy_to_single’ );

    Plugin Author wpexplorer

    (@wpexplorer)

    That works, except get_the_terms is not a cached function so I would recommend you use wp_get_post_terms instead which is cacheable to keep your site optimized ??

    – AJ

    Thread Starter Tonis_troubles

    (@tonis_troubles)

    OK, I changed it, thx for that!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Taxonomies missing in the body class’ is closed to new replies.