-
-
Save frankschrijvers/ab7b8a1a8bca6f46e345 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(function( $ ){ | |
$(".site-header").backstretch([BackStretchImg.src],{duration:3000,fade:750}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//* Do NOT include the opening php tag | |
add_action( 'wp_enqueue_scripts', 'sk_enqueue_backstretch' ); | |
/** | |
* Set Featured Image as Header's background using Backstretch on singular entries. | |
* For singular entries not having a Featured Image and other sections of the site, | |
* like category archives, a default image will be set as Header's background. | |
* | |
* @author Sridhar Katakam | |
* @link http://sridharkatakam.com/set-featured-image-headers-background-using-backstretch-genesis/ | |
*/ | |
function sk_enqueue_backstretch() { | |
wp_enqueue_script( 'backstretch', get_stylesheet_directory_uri() . '/js/jquery.backstretch.min.js', array( 'jquery' ), '', true ); | |
wp_enqueue_script( 'backstretch-set', get_stylesheet_directory_uri() . '/js/backstretch-set.js' , array( 'backstretch' ), '1.0.0', true ); | |
if ( has_post_thumbnail() && is_singular() ) { | |
$featured_image_url = wp_get_attachment_url( get_post_thumbnail_id() ); | |
$backstretch_src = array( 'src' => $featured_image_url ); | |
} else { | |
$default_header_url = get_stylesheet_directory_uri() . '/images/header-default.jpg'; | |
$backstretch_src = array( 'src' => $default_header_url ); | |
} | |
wp_localize_script( 'backstretch-set', 'BackStretchImg', $backstretch_src ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment