Skip to content

Instantly share code, notes, and snippets.

@nickdavis
Last active September 1, 2016 11:15
Show Gist options
  • Save nickdavis/372dd6cdd3030eaab98386ca7b92784b to your computer and use it in GitHub Desktop.
Save nickdavis/372dd6cdd3030eaab98386ca7b92784b to your computer and use it in GitHub Desktop.
Don't do backstretch on the Kickstart Pro homepage (not tested, assumes you're coding a custom solution instead)
<?php
add_action( 'wp_enqueue_scripts', 'kickstart_enqueue_backstretch_scripts' );
// Enqueue Backstretch script and prepare images for loading
function kickstart_enqueue_backstretch_scripts() {
// Don't do any backstretching on the homepage (CUSTOM)
if ( is_front_page() ) {
return;
}
// Load scripts only if custom background or featured image is being used
// If we're on a page with no featured image or background image, leave
if ( is_page() && ! has_post_thumbnail() && ! get_background_image() ) {
return;
}
// If we're not on a page and there's no background image, leave
if ( ! is_page() && ! get_background_image() ) {
return;
}
wp_enqueue_script( 'kickstart-backstretch', get_stylesheet_directory_uri() . '/js/backstretch.js', array( 'jquery' ), '2.0.4' );
wp_enqueue_script( 'kickstart-backstretch-set', get_stylesheet_directory_uri() . '/js/backstretch-set.js' , array( 'kickstart-backstretch' ), CHILD_THEME_VERSION );
wp_localize_script( 'kickstart-backstretch-set', 'KickstartBackStretchImg', array( 'src' => str_replace( 'http:', '', get_background_image() ) ) );
if ( is_home() ) {
wp_localize_script( 'kickstart-backstretch-set', 'KickstartBackStretchImg', array( 'src' => str_replace( 'http:', '', get_background_image() ) ) );
}
else if ( has_post_thumbnail() ) {
$image = array( 'src' => has_post_thumbnail() ? genesis_get_image( array( 'format' => 'url' ) ) : '' );
wp_localize_script( 'kickstart-backstretch-set', 'KickstartBackStretchImg', $image );
}
else {
wp_localize_script( 'milton-backstretch-set', 'KickstartBackStretchImg', array( 'src' => str_replace( 'http:', '', get_background_image() ) ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment