• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Custom Body Class style not being applied

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Custom Body Class style not being applied

This topic is: not resolved

Tagged: css, custom body class, html

  • This topic has 5 replies, 2 voices, and was last updated 12 years, 2 months ago by Lauren @ OnceCoupled.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • May 13, 2014 at 6:22 am #104883
    willb
    Member

    I've created a custom body class using this code snippet:

    //* Add custom body class to the head
    add_filter( 'body_class', 'sp_body_class' );
    function sp_body_class( $books ) {
    $books[] = 'custom-class';
    	return $books;
    }

    I've written the following CSS:

    .books {
    	border-bottom: 2px dotted #BDD3DB;
    	padding: 20px;
    	margin-bottom: 20px;
    	line-height: 1.00em;
    }

    With this HTML on a dev site it works (though this does not work on the intended site):

    <div class="books">
    some stuff here
    and more
    more 
    more stuff
    </div>
    
    <div class="books">
    a second class of books
    which has only two lines</div>
    
    <div class="books">
    a third type of stuff
    this one with lots of lines
    line
    line
    line
    </div>

    With this on the intended site it does not:

    <div class="books">
    <h3><a href="http://www.amazon.com/gp/product/0345434773/ref=as_li_tl?ie=UTF8&camp=1789&creative=390957&creativeASIN=0345434773&linkCode=as2&tag=themodemrsdar-20&linkId=HNA3TTCQHRTBQZRB" target="_blank">Evensong</a><img style="border: none !important; margin: 0px !important;" alt="" src="http://ir-na.amazon-adsystem.com/e/ir?t=themodemrsdar-20&l=as2&o=1&a=0345434773" width="1" height="1" border="0" /></h3>
    <em>by Gail Godwin</em><img style="border: none !important; margin: 0px !important;" alt="" src="http://ir-na.amazon-adsystem.com/e/ir?t=themodemrsdar-20&l=as2&o=1&a=0345434773" width="1" height="1" border="0" />
    
    <a href="http://www.amazon.com/gp/product/0345434773/ref=as_li_tl?ie=UTF8&camp=1789&creative=390957&creativeASIN=0345434773&linkCode=as2&tag=themodemrsdar-20&linkId=472MW3O7RUZLWH3W" target="_blank"><img class="alignleft  wp-image-18910" alt="Evensong" src="http://modernmrsdarcy.com/wp-content/uploads/2014/05/Evensong-192x300.jpg" width="150" height="225" /></a>Bacon ipsum dolor sit amet brisket short loin ball tip meatloaf fatback tongue swine. Shoulder pork loin tail, ribeye meatloaf bacon turkey flank bresaola turducken. Filet mignon biltong beef pork chop shoulder. Salami prosciutto ground round fatback swine sausage biltong.
    
    </div>

    The page is not published yet. But any guesses as to why the simple HTML works on one site and not on another? Is the CSS just not specific enough? Should I add .entry-content .books or something along those lines?

    http://modernmrsdarcy.com
    May 13, 2014 at 7:35 am #104895
    Lauren @ OnceCoupled
    Member

    The class you're adding is custom-class, not books.

    Best,
    Lauren


    We create mobile-first, PageSpeed-optimized, pixel-perfect custom themes! https://www.oncecoupled.com

    May 13, 2014 at 8:07 am #104908
    willb
    Member

    Thanks for the reply Lauren-

    so you're saying I should change the line

    $books[] = 'custom-class';
    

    to

    $books[] = 'books';

    That doesn't seem to change anything and still leaves me wondering why the exact same code would work in the dev environment, but not on the production site.

    Do you have an explanation as to what I've done wrong? Trying to learn as well as fix my problem 🙂

    May 13, 2014 at 8:12 am #104911
    Lauren @ OnceCoupled
    Member

    Well now it allows you to see (when using the browser inspector) that clicking on the body tag shows no .books styles being applied to it. That means the line in your code isn't being read. When I went into your CSS and grabbed that block of code, and copied it into the top of your file, is appears. This means your file is likely missing a closing bracket, keeping later code from being read.

    Best,
    Lauren


    We create mobile-first, PageSpeed-optimized, pixel-perfect custom themes! https://www.oncecoupled.com

    May 13, 2014 at 8:00 pm #105023
    willb
    Member

    Lauren I still cannot find the unclosed bracket or a comment that doesn't end, but it's working.

    Thanks for your help.

    May 13, 2014 at 8:32 pm #105028
    Lauren @ OnceCoupled
    Member

    You are missing multiple closing brackets: lines 1532 and 1641. If you close those and move your block of code back to the bottom, you should see it working still.


    We create mobile-first, PageSpeed-optimized, pixel-perfect custom themes! https://www.oncecoupled.com

  • Author
    Posts
Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble