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.

I have added this code to my child theme's functions.php file and use the new class but it styles the entire site, not the page I added to the code. What am I doing wrong?

add_filter('body_class','custom_body_class');

function custom_body_class($classes) {
    if( is_page('38034') ) {
        $classes[] = 'new-class';
        return $classes;
    }
}
share|improve this question
    
The code returns an error: > Warning: join() [function.join]: Invalid arguments passed in C:\Users\brad\Desktop\InstantWP_4.3\iwpserver\htdocs\wordpress\wp-includes\post-‌​template.php on line 393 class=""> –  Haymanpl Apr 30 '13 at 8:12
    
the return $classes; would need to be outside of the if( is_page() ) –  Michael Apr 30 '13 at 9:24
add comment

2 Answers 2

The ID can/should be given without quotes (otherwise if you a page with '38034' as slug/post_name, this will be used instead of the page with the ID 38034). And you want to return $classes no matter if you added your own or not.

add_filter('body_class', 'custom_body_class');
function custom_body_class($classes) {
    if (is_page(38034))
        $classes[] = 'new-class';
    return $classes;
}
share|improve this answer
add comment

Your function name does not match. Try this..

add_filter( 'body_class', 'custom_body_class' );

function custom_body_class( $classes ) {
    if ( is_page( '38034' ) ) {
        $classes[] = 'new-class';
        return $classes;
    }
}
share|improve this answer
    
I fixed that which was my mistake but i still get this error > Warning: join() [function.join]: Invalid arguments passed in C:\Users\brad\Desktop\InstantWP_4.3\iwpserver\htdocs\wordpress\wp-includes\post-‌​template.php on line 393 class=""> –  Haymanpl Apr 30 '13 at 8:13
    
Where are you adding this code? Try adding it to your functions.php file. –  ferne97 Apr 30 '13 at 8:16
add comment

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.