• 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

Add class to .site-inner only on certain pages based on custom body class.

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 › Add class to .site-inner only on certain pages based on custom body class.

This topic is: resolved

Tagged: add a class with a filter, adding a class to site-inner custom pages

  • This topic has 14 replies, 2 voices, and was last updated 8 years, 4 months ago by asbilly92.
Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • December 16, 2016 at 2:48 pm #197702
    asbilly92
    Participant

    Using a filter or hook...

    I would like to add a class to the .site-inner but only on specific pages, possibly using the custom body class I made with a filter or hook... ( I don't want it to affect all pages with that page template only a few) Can I use a filter SIMILAR this one but instead target the page via custom body class? This example uses the page template to target it....not what I need; or maybe this will work, need a little help getting it figured out!

    Something like this:

    add_filter( 'genesis_attr_site-inner', 'custom_add_css_attr' );
    
    function custom_add_css_attr( $attributes ) { 
        if ( is_page_template( 'page_blog.php' ) ) { 
            $attributes['class'] .= ' new-custom-class-here'; 
        } 
       return $attributes; 
    }
    December 16, 2016 at 3:13 pm #197703
    Victor Font
    Moderator

    Instead of is_page_template you can use is_page ( array( '1', '2', '3', '4') ) where the numbers are the page_ids.


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    December 16, 2016 at 3:31 pm #197706
    asbilly92
    Participant

    Ok great so my possible corrected filter may look like this:

    add_filter( 'genesis_attr_site-inner', 'custom_add_css_attr' );
    
    function custom_add_css_attr( $attributes ) { 
        if ( is_page ( array('1','2','3' ) ) { 
            $attributes['class'] .= ' new-custom-class'; 
        } 
       return $attributes; 
    }

    I kind of realized that the page_template one was wrong lol..

    December 16, 2016 at 7:06 pm #197713
    Victor Font
    Moderator

    Yes, you just need to use the correct page ids.


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    December 17, 2016 at 7:47 am #197729
    asbilly92
    Participant

    Oh yes, of course. I will give it a shot!

    Thank you very much! 🙂

    December 19, 2016 at 9:31 am #197828
    asbilly92
    Participant

    Victor,

    This is what I added and DreamWeaver says there is a problem; on the line that contains the is_page. Do you know why?

    add_filter( 'genesis_attr_site-inner', 'custom_add_css_attr' );
    
    function custom_add_css_attr( $attributes ) { 
        if ( is_page ( array('10','140' ) ) { 
            $attributes['class'] .= 'blurr-effect'; 
        } 
       return $attributes; 
    }
    December 19, 2016 at 9:51 am #197829
    asbilly92
    Participant

    Does it make a difference that I'm using a Child Theme ?

    December 19, 2016 at 1:00 pm #197832
    Victor Font
    Moderator

    There shouldn't be a space between is_page and the opening paren.


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    December 19, 2016 at 5:26 pm #197847
    asbilly92
    Participant

    Oh geeze, I stared at that thing for a long time!

    December 20, 2016 at 11:54 am #197905
    asbilly92
    Participant

    Uggg I'm still getting an error on that same line, I removed the space where you advised me too; but still get an error . . . frustrating 😉

    //* For adding class to site inner on certain pages
    add_filter( 'genesis_attr_site-inner', 'custom_add_css_attr' );
    
    function custom_add_css_attr( $attributes ) { 
        if ( is_page( array('10','140') ) { 
            $attributes['class'] .= ' blurr-effect'; 
        } 
       return $attributes; 
    }
    
    December 20, 2016 at 12:42 pm #197913
    Victor Font
    Moderator

    Let's try it this way:

    //* For adding class to site inner on certain pages
    add_filter( 'genesis_attr_site-inner', 'custom_add_css_attr' );
    
    function custom_add_css_attr( $attributes ) { 
        $pages = array( '10', '140' );
        if ( is_page( $pages ) { 
            $attributes['class'] .= ' blurr-effect'; 
        } 
       return $attributes; 
    }

    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    December 20, 2016 at 2:41 pm #197925
    asbilly92
    Participant

    Ok wow great, thank you ! Will try later and post back!

    December 21, 2016 at 7:29 am #197939
    asbilly92
    Participant

    OK .... well now it's giving me an error on the line: if ( is_page( $pages ) {

    Gotta luv php.....

    December 21, 2016 at 2:21 pm #197959
    Victor Font
    Moderator

    Sorry, missing another ). Here's the corrected code:

    //* For adding class to site inner on certain pages
    add_filter( 'genesis_attr_site-inner', 'custom_add_css_attr' );
    
    function custom_add_css_attr( $attributes ) { 
        $pages = array( '10', '140' );
        if ( is_page( $pages ) ) { 
            $attributes['class'] .= ' blurr-effect'; 
        } 
       return $attributes; 
    }

    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    December 22, 2016 at 7:38 am #197999
    asbilly92
    Participant

    Oh man I should have actually caught that too, wow ok cool!

    It works! Perfect!

    Thank you for all of your effort!!

  • Author
    Posts
Viewing 15 posts - 1 through 15 (of 15 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

© 2025 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