• 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

set background image conditionally

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 › General Discussion › set background image conditionally

This topic is: not a support question
  • This topic has 5 replies, 3 voices, and was last updated 5 years, 10 months ago by ftleow.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • July 10, 2019 at 11:03 am #492267
    ftleow
    Participant

    Hi guys,

    I've set a background image at .site-inner section.

    I'm trying to get it to display only if it is front-page.

    
    if ( ! is_front_page() || ! get_background_image() )
    		return;
    

    Can someone help with how to go with this? If I use add_action, which section should I use to output it? as I want the bg image to be in .site-inner section.

    Or if you have any other recommended solutions for this?

    Thank you.

    Btw, the code I try to use is from this website. Thanks.

    July 15, 2019 at 8:22 am #492368
    Genesis Developer
    Member

    which child theme are you using? Can you share your current code? We shall look it.


    Download Genesis Featured Posts Combo Widget | Simple Grid Layouts Plugin for Posts, CPTs and terms
    You can request new tips/help.

    July 15, 2019 at 10:22 pm #492379
    ftleow
    Participant

    Hi Genesis Developer,

    I'm using Enterprise Pro theme. Thanks for willing to look. The last thing I want to do is to change the structure of the CSS, which is what I am about to do within these 2 days. After which I will set the background image to be in the widget section instead.

    But my option to use the background image in .site-inner is still open if I can set it to display only in front page.

    I tried to enqueue another css file which contains:

    
    /* Siteinner
    ---------------------------------------------------------------------------------------------------- */
    
    .siteinner .site-inner {
    	
    	background-color: #f5f5f5; 
    	background-image: url(images/bg.png);
    	background-repeat: repeat-x;
    	border-top: 1px solid #ececec;
    	clear: both;
    	
    }
    

    The enqueue I use is (inside the existing enqueue scripts from the theme):

    
    if ( is_front_page()|| is_home() ) {
    		
    	wp_enqueue_style( 'inner-bg-style', get_stylesheet_directory_uri() . '/css/inner-style.css' );
    		
    	}
    

    There's no error, just not showing the bg image on front page. I checked the console, the additional css file is enqueued successfully though.

    July 16, 2019 at 11:12 am #492388
    Genesis Developer
    Member

    I am pretty sure that it .siteinner is a wrong CSS classname. You can try this css

    .home .site-inner {
    	
    	background-color: #f5f5f5; 
    	background-image: url(images/bg.png);
    	background-repeat: repeat-x;
    	border-top: 1px solid #ececec;
    	clear: both;
    	
    }

    Download Genesis Featured Posts Combo Widget | Simple Grid Layouts Plugin for Posts, CPTs and terms
    You can request new tips/help.

    July 17, 2019 at 6:05 am #492400
    tripnetra236
    Member

    Use This Code and Check this out.
    This is the Only Working Code i Find.
    <script type="text/javascript">
    $(document).ready(function(){
    if (combo.hcs <= 10) && (combo.hcs >= 1)
    $(".myClass").css("background-image", "url('BB.png')";
    else if (combo.hcs <= 20) && (combo.hcs >= 11)
    $(".myClass").css("background-image", "url('BH.png')";
    else if (combo.hcs <= 30) && (combo.hcs >= 21)
    $(".myClass").css("background-image", "url('BM.png')";
    else if (combo.hcs <= 40) && (combo.hcs >= 31)
    $(".myClass").css("background-image", "url('HB.png')";
    else if (combo.hcs <= 50) && (combo.hcs >= 41)
    $(".myClass").css("background-image", "url('HH.png')";
    else if (combo.hcs <= 60) && (combo.hcs >= 51)
    $(".myClass").css("background-image", "url('HM.png')";
    else if (combo.hcs <= 70) && (combo.hcs >= 61)
    $(".myClass").css("background-image", "url('MB.pmg')";
    else if (combo.hcs <= 80) && (combo.hcs >= 71)
    $(".myClass").css("background-image", "url('MH.png')";
    else if (combo.hcs <= 99) && (combo.hcs >= 81)
    $(".myClass").css("background-image", "url('MM.png')";
    }
    </script>

    July 17, 2019 at 9:18 pm #492408
    ftleow
    Participant

    Thanks Genesis Developer. I'm a bit tight with some other tasks' timeline. Haven't tried it, but thanks.

    Guys, please stop replying to this thread, this has probably gone off topic a bit.

    Thanks.

  • Author
    Posts
Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘General Discussion’ 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