WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Undefined Variable (5 posts)

  1. Red Deer Web Design
    Member
    Posted 2 years ago #

    Hey guys, I'm creating a theme and have debug turned on.

    I added: <?php body_class($class); ?> to my <body>

    Now I'm getting this Notice on every page. Anything I can do to remove the notice?

    Notice: Undefined variable: class in /Users/bdbolin/Desktop/MAMP/wp-content/themes/Oasis/index.php on line 2
    class="page page-id-174 page-parent page-template-default">
  2. popper
    Member
    Posted 2 years ago #

    Either define the variable, or turn error reporting for notices off.

  3. Try changing it to <body <?php body_class(); ?>> instead.

  4. Red Deer Web Design
    Member
    Posted 2 years ago #

    @Christine - I think that worked! Thanks guys! Can you tell me how that's different than what I put? Like is there a different instance that mine would have worked better?

  5. If you read the codex - http://codex.wordpress.org/Function_Reference/body_class
    You'll see that $class, is optional & can be either an array of class names or a string with space-separated classes names. So it needs to be defined. I never use it and just let WordPress set the classes.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.