• 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

Background-image on other pages

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 › Background-image on other pages

This topic is: resolved

Tagged: background image, front-page.php

  • This topic has 14 replies, 5 voices, and was last updated 9 years, 6 months ago by Marcy.
Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • January 6, 2016 at 7:21 pm #175808
    Eduardo
    Member

    I'm currently working on the Agency Pro theme.

    How do I remove the background image from all pages except the front-page.php?

    I've covered it using a lot of margin and padding on the content but it's still there. I'd like to remove it.

    http://staging.trytobosa.org
    January 6, 2016 at 11:59 pm #175825
    Marcy
    Participant

    You would find the section - //* Enqueue Backstretch script and prepare images for loading - in functions.php
    and change it by adding the "if ( is_front_page() )", with the included brackets, like:

    //* Enqueue Backstretch script and prepare images for loading
    add_action( 'wp_enqueue_scripts', 'agency_enqueue_backstretch_scripts' );
    function agency_enqueue_backstretch_scripts() {
    
    if ( is_front_page() ) {
    	//* Load scripts only if custom background is being used
    	if ( ! get_background_image() )
    		return;
    
    	wp_enqueue_script( 'agency-pro-backstretch', get_bloginfo( 'stylesheet_directory' ) . '/js/backstretch.js', array( 'jquery' ), '1.0.0' );
    	wp_enqueue_script( 'agency-pro-backstretch-set', get_bloginfo( 'stylesheet_directory' ).'/js/backstretch-set.js' , array( 'jquery', 'agency-pro-backstretch' ), '1.0.0' );
    
    	wp_localize_script( 'agency-pro-backstretch-set', 'BackStretchImg', array( 'src' => str_replace( 'http:', '', get_background_image() ) ) );
    	}
    }

    Marcy | Amethyst Website Design | Twitter

    January 8, 2016 at 2:11 am #175918
    Eduardo
    Member

    Thanks for responding Marcy. My code has something a tiny bit different.
    Here's the original code:

    //* Enqueue Backstretch script and prepare images for loading
    add_action( 'wp_enqueue_scripts', 'agency_enqueue_backstretch_scripts' );
    function agency_enqueue_backstretch_scripts() {
    
    	$image = get_option( 'agency-backstretch-image', sprintf( '%s/images/bg.jpg', get_stylesheet_directory_uri() ) );
    
    	//* Load scripts only if custom backstretch image is being used
    	if ( ! empty( $image ) ) {
    
    		wp_enqueue_script( 'agency-pro-backstretch', get_bloginfo( 'stylesheet_directory' ) . '/js/backstretch.js', array( 'jquery' ), '1.0.0' );
    		wp_enqueue_script( 'agency-pro-backstretch-set', get_bloginfo( 'stylesheet_directory' ).'/js/backstretch-set.js' , array( 'jquery', 'agency-pro-backstretch' ), '1.0.0' );
    
    		wp_localize_script( 'agency-pro-backstretch-set', 'BackStretchImg', array( 'src' => str_replace( 'http:', '', $image ) ) );
    	}
    }

    Here's what I added trying to try and follow your directions:

    //* Enqueue Backstretch script and prepare images for loading
    add_action( 'wp_enqueue_scripts', 'agency_enqueue_backstretch_scripts' );
    function agency_enqueue_backstretch_scripts() {
    
    	$image = get_option( 'agency-backstretch-image', sprintf( '%s/images/bg.jpg', get_stylesheet_directory_uri() ) );
    
    if ( is_front_page() ) {
    		//* Load scripts only if custom backstretch image is being used
    		if ( ! empty( $image ) ) {
    
    			wp_enqueue_script( 'agency-pro-backstretch', get_bloginfo( 'stylesheet_directory' ) . '/js/backstretch.js', array( 'jquery' ), '1.0.0' );
    			wp_enqueue_script( 'agency-pro-backstretch-set', get_bloginfo( 'stylesheet_directory' ).'/js/backstretch-set.js' , array( 'jquery', 'agency-pro-backstretch' ), '1.0.0' );
    
    			wp_localize_script( 'agency-pro-backstretch-set', 'BackStretchImg', array( 'src' => str_replace( 'http:', '', $image ) ) );
    
    		}
    	}
    }

    Unfortunately, the background image is still loading on other pages.

    January 8, 2016 at 2:13 am #175919
    Brad Dalton
    Participant

    Another option is to take the code from your functions file and paste it into your front-page.php file so its only loads in that template.


    Tutorials for StudioPress Themes.

    January 8, 2016 at 4:24 am #175930
    Eduardo
    Member

    Thanks Braddalton. I cut and pasted the code into front-page.php, but unfortunately, it's still loading on my other pages. Hmm.

    January 8, 2016 at 5:21 am #175937
    Brad Dalton
    Participant

    Did you delete it from your functions file?


    Tutorials for StudioPress Themes.

    January 8, 2016 at 6:40 am #175943
    naczel
    Member

    Thanks for responding Marcy. My code has something a tiny bit different.

    January 8, 2016 at 9:40 am #175968
    dev
    Participant

    Braddalton, et. al.:

    Could you do this by giving all your pages and posts a class like "internal-page-post" and use this class in CSS like:

    .internal-page-post { background: white !important;}

    There might be more classes to add to the above selector, but would it work? Or is code the only/best way to do this?

    Most of you folks (especially braddalton) are better at CSS than I will ever be!

    January 8, 2016 at 10:53 am #175972
    Marcy
    Participant

    Yes, you can add the is_front_page() conditional to functions.php, OR you can cut and paste the original, unedited function from functions.php into front_page.php.

    Also be sure to clear the server cache, and also your browser cache.


    Marcy | Amethyst Website Design | Twitter

    January 10, 2016 at 8:09 am #176139
    Brad Dalton
    Participant

    @dev Yes, don't see why not. I'm sure there are many different methods to achieve the same result. Thanks for your support.


    Tutorials for StudioPress Themes.

    January 12, 2016 at 6:31 pm #176333
    Eduardo
    Member

    @braddalton, I did indeed delete the code from the functions.php file. Is this a problem?

    January 12, 2016 at 6:36 pm #176334
    Eduardo
    Member

    @Marcy, I'm currently doing my work in local environment. How do I clear the server cache in this situation?

    January 12, 2016 at 7:06 pm #176337
    Marcy
    Participant

    OK. I l added the theme to local to test again, and this is what I did.

    1. I looked at the code again, and a better way of writing it in functions.php is to combine the if statements. I don't think it was needed, but that's what I tested for you.

    //* Enqueue Backstretch script and prepare images for loading
    add_action( 'wp_enqueue_scripts', 'agency_enqueue_backstretch_scripts' );
    function agency_enqueue_backstretch_scripts() {
    
    	$image = get_option( 'agency-backstretch-image', sprintf( '%s/images/bg.jpg', get_stylesheet_directory_uri() ) );
    	
    	//* Load scripts only if custom backstretch image is being used
    	if ( ! empty( $image ) && is_front_page() ) {
    
    		wp_enqueue_script( 'agency-pro-backstretch', get_bloginfo( 'stylesheet_directory' ) . '/js/backstretch.js', array( 'jquery' ), '1.0.0' );
    		wp_enqueue_script( 'agency-pro-backstretch-set', get_bloginfo( 'stylesheet_directory' ).'/js/backstretch-set.js' , array( 'jquery', 'agency-pro-backstretch' ), '1.0.0' );
    
    		wp_localize_script( 'agency-pro-backstretch-set', 'BackStretchImg', array( 'src' => str_replace( 'http:', '', $image ) ) );
    	
    	}
    }

    2. Go to Appearance > Customize and then Background Image. Delete and save any image that you have there.
    Now check the outside (not the view in the customizer). Reload home page. Is there an image on the home page? Is there no image on other pages?
    If image is not just on home page, do Step 3.

    3. Go to Appearance > Customize. This time, click Backstretch image. Remove any image that is there and Save. Then you can add a different image and Save (it doesn't matter what it is.). Then remove that image and add the other one back. Save and all should be good.


    Marcy | Amethyst Website Design | Twitter

    January 14, 2016 at 3:11 pm #176513
    Eduardo
    Member

    Thank you, Marcy. This worked great!

    January 14, 2016 at 5:34 pm #176528
    Marcy
    Participant

    You're welcome, Eduardo! Glad it worked for you.


    Marcy | Amethyst Website Design | Twitter

  • Author
    Posts
Viewing 15 posts - 1 through 15 (of 15 total)
  • The topic ‘Background-image on other pages’ is closed to new 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