Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Here is what I have so far in my functions.php.

add_filter('body_class','cp_new_body_classes');
function cp_new_body_classes($classes) {
    if( !is_page_template() ) {
        $classes[] = 'reg-page';
    return $classes;
    }
}

I'm trying to append the class of reg-page to pages that are not page templates. For the pages that are page templates, I just want to leave the classes as they are. When trying the code above, the class of reg-page gets added like I want to pages which are not page templates but the other pages (which are page templates) get left with no classes at all. How can I fix this code?

share|improve this question
    
You should put your answer as an answer to your question (in the answer form) and accept it, to mark the question as resolved. –  mike23 Jul 13 '11 at 16:41

1 Answer 1

add_filter('body_class','cp_new_body_classes');
function cp_new_body_classes($classes) {
    if( !is_page_template() )
        $classes[] = 'reg-page';

    return $classes;
}

The problem was that you are only returning the classes if !is_page_template(), but you want to return the classes always as it contains the other classes you didn't add yourself in an array, you just want to add some then return them like normal.

share|improve this answer
1  
yup, always return $classes –  helgatheviking Feb 24 '12 at 4:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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