user1617218
user1617218

Reputation:

Add body class wordpress error

I´m using this code to add class to the body depending on the page:

    <?php

    // add a custom body class
    add_action( 'body_class', 'ilwp_add_my_bodyclass');
    function ilwp_add_my_bodyclass( $classes ) {
        if ( is_page( '12' ))
            {
                $classes[] = 'login';
                return $classes;
            }
        else if ( is_page( '9' ))
            {
                $classes[] = 'homepage';
                return $classes;
            }   
    }

    ?>

It works when i´m navigating thru static pages, but when I go to a single post I get this error:

Warning: join() [function.join]: Invalid arguments passed in /Users/diego/Sites/bb/wp-includes/post-template.php on line 389 class="">

Any idea why is that happening?

Upvotes: 0

Views: 709

Answers (1)

Marcelo Rodovalho
Marcelo Rodovalho

Reputation: 923

You forgot the 'else' statement. Let the 'return' out of if-else statement. Maybe you need to do this:

<?php add_action( 'body_class', 'ilwp_add_my_bodyclass');
function ilwp_add_my_bodyclass( $classes ) {
    if ( is_page( '12' ))
        {
            $classes[] = 'login';
         }
    else if ( is_page( '9' ))
        {
            $classes[] = 'homepage';
        }   
    return $classes
} ?>

Upvotes: 1

Related Questions