Forked from michaelcarwile/backstretch-genesis-functions.php
Created
February 26, 2014 02:23
-
-
Save jamiemitchell/9222297 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
<?php | |
//* don't copy php tag above | |
//* add following code to functions.php: | |
//* Load backstretch js | |
/** Add metabox for backstretch default/fallback background image */ | |
add_action( 'genesis_theme_settings_metaboxes', 'themename_theme_settings_metaboxes', 10, 1 ); | |
function themename_theme_settings_metaboxes( $pagehook ) { | |
add_meta_box( 'themename-default-background-image', __( 'Background - Default Image', 'themename' ), 'themename_default_background_image_metabox', $pagehook, 'main', 'high' ); | |
} | |
/** Content for the default/fallback image metabox */ | |
function themename_default_background_image_metabox() { | |
printf( '<label for="%s[%s]" /><br />', GENESIS_SETTINGS_FIELD, 'themename_default_image' ); | |
printf( '<input type="text" name="%1$s[%2$s]" id="%1$s[%1$s]" size="75" value="%3$s" />', GENESIS_SETTINGS_FIELD, 'themename_default_image', genesis_get_option( 'themename_default_image' ) ); | |
} | |
/** Load Backstretch script and prepare images for loading */ | |
add_action( 'wp_enqueue_scripts', 'themename_enqueue_scripts' ); | |
function themename_enqueue_scripts() { | |
if ( ! genesis_get_option( 'themename_default_image' ) && ! has_post_thumbnail() ) | |
return; | |
wp_enqueue_script( 'themename-backstretch', get_bloginfo( 'stylesheet_directory' ) . '/js/backstretch.js', array( 'jquery' ), '1.0.0', true ); | |
wp_enqueue_script( 'themename-backstretch-set', get_bloginfo('stylesheet_directory').'/js/backstretch-set.js' , array( 'jquery', 'themename-backstretch' ), '1.0.0', true ); | |
} | |
add_action( 'genesis_after', 'themename_set_background_image' ); | |
function themename_set_background_image() { | |
$image = array( 'src' => has_post_thumbnail() ? genesis_get_image( array( 'format' => 'url' ) ) : genesis_get_option( 'themename_default_image' ) ); | |
wp_localize_script( 'themename-backstretch-set', 'BackStretchImg', $image ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there, is this gist for adding metabox for backstretch in order to replace edition of js file ?