Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to add support for custom backgrounds in CPTs. https://sridharkatakam.com/how-to-add-support-for-custom-backgrounds-in-cpts/
// add support for custom background to single WooCommerce product pages
add_post_type_support( 'product', 'custom-background' );
//* 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 ) ) );
}
//* Load scripts only if custom backstretch image is being used
if ( ! empty( $image ) ) {
if ( is_singular( 'product' ) ) {
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:', '', $image ) ) );
}
if ( is_singular( 'product' ) ) {
$image = get_background_image();
}
$image = get_option( 'agency-backstretch-image', sprintf( '%s/images/bg.jpg', get_stylesheet_directory_uri() ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.