Title: Function to load on homepage only in function.php
Last modified: August 20, 2016

---

# Function to load on homepage only in function.php

 *  [bubaphex](https://wordpress.org/support/users/bubaphex/)
 * (@bubaphex)
 * [14 years ago](https://wordpress.org/support/topic/function-to-load-on-homepage-only-in-functionphp/)
 * Hi All,
 * is there a way to put conditions around
 *     ```
       function wpsc_deregister_scripts() {
       	wp_deregister_script( 'wpsc-thickbox' );
       	wp_deregister_script( 'jquery-rating' );
       	wp_deregister_script( 'wp-e-commerce' );
       	wp_deregister_script( 'jQuery' );
       	wp_deregister_script( 'infieldlabel' );
       	wp_deregister_script( 'wp-e-commerce-ajax-legacy' );
       	wp_deregister_script( 'wp-e-commerce-dynamic' );
       	wp_deregister_script( 'livequery' );
       	wp_deregister_script( 'wp-e-commerce-legacy' );
       	wp_deregister_script( 'l10n' );
       	wp_deregister_script( 'wpsc-gold-cart' );
       }
       add_action( 'wp_print_scripts', 'wpsc_deregister_scripts', 100 );
       ```
   
 * Basically i want that to stop working on one section of my website.
 * Basicly it turns off the JS for WP ecommerce which loads regarless of what page
   you are on.

Viewing 8 replies - 1 through 8 (of 8 total)

 *  [Sennza Pty Ltd](https://wordpress.org/support/users/sennza/)
 * (@sennza)
 * [14 years ago](https://wordpress.org/support/topic/function-to-load-on-homepage-only-in-functionphp/#post-2804588)
 * You can put a conditional around it such as:
 *     ```
       if ( is_home() || is_front_page() ) {
       function wpsc_deregister_scripts() {
       	wp_deregister_script( 'wpsc-thickbox' );
       	wp_deregister_script( 'jquery-rating' );
       	wp_deregister_script( 'wp-e-commerce' );
       	wp_deregister_script( 'jQuery' );
       	wp_deregister_script( 'infieldlabel' );
       	wp_deregister_script( 'wp-e-commerce-ajax-legacy' );
       	wp_deregister_script( 'wp-e-commerce-dynamic' );
       	wp_deregister_script( 'livequery' );
       	wp_deregister_script( 'wp-e-commerce-legacy' );
       	wp_deregister_script( 'l10n' );
       	wp_deregister_script( 'wpsc-gold-cart' );
       }
       add_action( 'wp_print_scripts', 'wpsc_deregister_scripts', 100 );
       }
       ```
   
 * I added both the is_home and is_front_page seeing I’m not sure if you have a 
   static home page for your front page or a list of blog posts. Hope that helps!
 *  Thread Starter [bubaphex](https://wordpress.org/support/users/bubaphex/)
 * (@bubaphex)
 * [14 years ago](https://wordpress.org/support/topic/function-to-load-on-homepage-only-in-functionphp/#post-2804644)
 * Thanks for the suggestion Unfortunately it didn’t work for me, is there another
   way to do it?
 * i was thinking of doing it via URI segments how-ever i doubt that would work.
 *  [Sennza Pty Ltd](https://wordpress.org/support/users/sennza/)
 * (@sennza)
 * [14 years ago](https://wordpress.org/support/topic/function-to-load-on-homepage-only-in-functionphp/#post-2804645)
 * Ahh I didn’t pay enough attention to your code before. You’re using wp_print_scripts
   when you’re probably after wp_enqueue_scripts.
 * Try this:
 *     ```
       if ( is_home() || is_front_page() ) {
       function wpsc_deregister_scripts() {
       	wp_deregister_script( 'wpsc-thickbox' );
       	wp_deregister_script( 'jquery-rating' );
       	wp_deregister_script( 'wp-e-commerce' );
       	wp_deregister_script( 'jQuery' );
       	wp_deregister_script( 'infieldlabel' );
       	wp_deregister_script( 'wp-e-commerce-ajax-legacy' );
       	wp_deregister_script( 'wp-e-commerce-dynamic' );
       	wp_deregister_script( 'livequery' );
       	wp_deregister_script( 'wp-e-commerce-legacy' );
       	wp_deregister_script( 'l10n' );
       	wp_deregister_script( 'wpsc-gold-cart' );
       }
       add_action( 'wp_enqueue_scripts', 'wpsc_deregister_scripts', 10 );
       }'
       ```
   
 * If that doesn’t work then try changing the priority down from 10 to maybe 9. 
   The 100 you had in your example is very late.
 * Also `wp_deregister_script( 'jQuery' );` might not work so maybe try `wp_deregister_script('
   jquery' );`
 * I’d be very careful deregistering jQuery as well because so many plugins and 
   themes use it these days.
 * And if that doesn’t work still trying using:
 * `if ( is_page( 54 ) ) {`
 * as your conditional statement where 54 is the page ID of your homepage. Hopefully
   that might get you on the right track!
 *  [Oliver Farrell](https://wordpress.org/support/users/oliverfarrell/)
 * (@oliverfarrell)
 * [14 years ago](https://wordpress.org/support/topic/function-to-load-on-homepage-only-in-functionphp/#post-2804646)
 * What Bronson suggested should work just fine (if the homepage/front page are 
   the pages you want to disable the scripts).
 * If there is a specific page/s you wish to disable the scripts on, do the following.
 *     ```
       if ( is_page('about') || is_page('hello-world') ) {
       function wpsc_deregister_scripts() {
       	wp_deregister_script( 'wpsc-thickbox' );
       	wp_deregister_script( 'jquery-rating' );
       	wp_deregister_script( 'wp-e-commerce' );
       	wp_deregister_script( 'jQuery' );
       	wp_deregister_script( 'infieldlabel' );
       	wp_deregister_script( 'wp-e-commerce-ajax-legacy' );
       	wp_deregister_script( 'wp-e-commerce-dynamic' );
       	wp_deregister_script( 'livequery' );
       	wp_deregister_script( 'wp-e-commerce-legacy' );
       	wp_deregister_script( 'l10n' );
       	wp_deregister_script( 'wpsc-gold-cart' );
       }
       add_action( 'wp_print_scripts', 'wpsc_deregister_scripts', 100 );
       }
       ```
   
 * Alternatively, if there is a top-level page and it’s sub pages you wish the disable
   the scripts one, try looking into the ‘is_tree()’ function.
 *  [Oliver Farrell](https://wordpress.org/support/users/oliverfarrell/)
 * (@oliverfarrell)
 * [14 years ago](https://wordpress.org/support/topic/function-to-load-on-homepage-only-in-functionphp/#post-2804647)
 * Oops, that’ll teach me to post before refreshing. Bronson’s suggestion should
   work just fine.
 *  [Sennza Pty Ltd](https://wordpress.org/support/users/sennza/)
 * (@sennza)
 * [14 years ago](https://wordpress.org/support/topic/function-to-load-on-homepage-only-in-functionphp/#post-2804648)
 * Haha looks like we posted at the same time Oliver! 🙂
 * If you’re using is_page with the page slug then I’d recommend using an array 
   just in case someone changes the slug name down the track so I’d do something
   like:
 * `if ( is_page( array ( 2, 'about', 'About Me' ) ) ) {`
 * That way it’ll look for the page ID first, the slug second then the title. I 
   learnt the hard way when I used just the slug as a conditional once for a client
   and they changed the slug name on me and my conditional logic broke 🙁
 * Normally I would’ve done the full array but seeing bubaphex didn’t add a link
   to their URL I couldn’t be as specific 🙂
 *  [Oliver Farrell](https://wordpress.org/support/users/oliverfarrell/)
 * (@oliverfarrell)
 * [14 years ago](https://wordpress.org/support/topic/function-to-load-on-homepage-only-in-functionphp/#post-2804649)
 * Ah! That would make sense 🙂 That could save me a lot of messing about.
 *  Thread Starter [bubaphex](https://wordpress.org/support/users/bubaphex/)
 * (@bubaphex)
 * [14 years ago](https://wordpress.org/support/topic/function-to-load-on-homepage-only-in-functionphp/#post-2804741)
 * Thanks for you help guys,
 * Ive tried the above but didnt work for me, even tried page specific to which 
   i had no luck.
 * perhaps im mis-understanding where i should put this, should this be on the functions.
   php (which is where i have it now) or does this go on the page it self?

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Function to load on homepage only in function.php’ is closed to new replies.

## Tags

 * [Ecommerce](https://wordpress.org/support/topic-tag/ecommerce/)
 * [wp ecommerce](https://wordpress.org/support/topic-tag/wp-ecommerce/)

 * 8 replies
 * 3 participants
 * Last reply from: [bubaphex](https://wordpress.org/support/users/bubaphex/)
 * Last activity: [14 years ago](https://wordpress.org/support/topic/function-to-load-on-homepage-only-in-functionphp/#post-2804741)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
