• Resolved tagtag

    (@tagtag)


    Hello,
    i’d like to display folder slug on body class to make out different group of page. Could you tell me how could I do ?

    Thanks !

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author wickedplugins

    (@wickedplugins)

    Hi @tagtag,

    Sure, see the code below for an example of how you can accomplish that. Hope this helps!

    // Add body class filter
    add_filter( 'body_class', 'custom_body_classes' );
    
    function custom_body_classes( $classes ) {
    
    	// Folder taxonomies are named in the format 'wicked_{$post_type}_folders'
    	$taxonomy = 'wicked_' . get_post_type() . '_folders';
    
    	// Get slugs of folders that the current post belongs to
    	$folders = wp_get_object_terms( get_the_ID(), $taxonomy, array( 'fields' => 'slugs' ) );
    
    	// Merge the folder slugs into the body classes array
    	$classes = array_merge( $classes, $folders );
    
    	return $classes;
    
    }
    Plugin Author wickedplugins

    (@wickedplugins)

    Hi @tagtag,

    I’m going to mark this support request as closed but, if the above answer didn’t address your question, please feel free to post another comment. Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘display folder slug in body_class’ is closed to new replies.