Community Forums › Forums › Archived Forums › General Discussion › Background-image on other pages
Tagged: background image, front-page.php
- This topic has 14 replies, 5 voices, and was last updated 8 years, 11 months ago by Marcy.
-
AuthorPosts
-
January 6, 2016 at 7:21 pm #175808EduardoMember
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.orgJanuary 6, 2016 at 11:59 pm #175825MarcyParticipantYou 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 #175918EduardoMemberThanks 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 #175919Brad DaltonParticipantAnother 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.
January 8, 2016 at 4:24 am #175930EduardoMemberThanks 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 #175937Brad DaltonParticipantJanuary 8, 2016 at 6:40 am #175943naczelMemberThanks for responding Marcy. My code has something a tiny bit different.
January 8, 2016 at 9:40 am #175968devParticipantBraddalton, 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 #175972MarcyParticipantYes, 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 #176139Brad DaltonParticipant@dev Yes, don't see why not. I'm sure there are many different methods to achieve the same result. Thanks for your support.
January 12, 2016 at 6:31 pm #176333EduardoMember@braddalton, I did indeed delete the code from the functions.php file. Is this a problem?
January 12, 2016 at 6:36 pm #176334EduardoMember@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 #176337MarcyParticipantOK. 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 #176513EduardoMemberThank you, Marcy. This worked great!
January 14, 2016 at 5:34 pm #176528MarcyParticipant -
AuthorPosts
- The topic ‘Background-image on other pages’ is closed to new replies.