0

I'm trying to edit classes in the body tag for custom post types so I can display the pages full width using the WooThemes Canvas built in full width class - instead of overriding it.

By default it seems the body class is set to 'two-col-right' and 'two-col-right-1080' for custom post types, I need them to be 'one-col' and 'one-col-1080'

Simple you would think, but it seems there is no way to edit a class, only a way to filter it out and add a new one?

It does add the 2 classes now but the old ones are not filtered out. can anyone see any issues with my code or is there an easier way to do this? thanks

this WordPress Answers post is very similar

The code so far is:

//*** make Services full col ***/
add_filter( 'body_class', 'custom_post_full_width', 'very late please', 2 );
function custom_post_full_width( $wp_classes, $extra_classes ) {
if ( is_archive('services') OR is_singular('services') ) {

// List of the only WP generated classes that are not allowed
$blacklist = array('two-col-right', 'two-col-right-1080');
// Blacklist result
$wp_classes = array_diff( $wp_classes, $blacklist );
// Extra classes to add
$extra_classes = array('one-col','one-col-1080');
}

// Add the extra classes back untouched
return array_merge( $wp_classes, (array) $extra_classes );
}

Not working though :(

i'm using funcions.php with a child theme of Canvas

0

1 Answer 1

2

try this

//*** make Services full col ***/
add_filter( 'body_class', 'custom_post_full_width', 999, 2 );
function custom_post_full_width( $wp_classes, $class ) {
    if ( is_post_type_archive('services') OR is_singular('services') ) {

        // List of the only WP generated classes that are not allowed
        $blacklist = array('two-col-right', 'two-col-right-1080');

        // Blacklist result
        $wp_classes = array_diff( $wp_classes, $blacklist );

        // Extra classes to add
        $wp_classes = array_merge( $wp_classes, array('one-col','one-col-1080') );

    }

    // Add the extra classes back untouched
    return $wp_classes;
}
  1. use is_post_type_archive( $post_type )
1
  • amazing, thanks Ravs, now it is working perfectly and I'll be able to sleep again at night, thanks :)
    – morktron
    Commented Dec 3, 2013 at 1:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.