Help With Conditional Background Image, Based on Page/Parent
-
Could use a little help with this functions.php hack.
I am running a Genesis theme, Agency Pro. I have the following code pasted into functions:
// Grant's Conditional BKGRND Images! if (is_page('53') || 53 == $post->post_parent ) : wp_localize_script( 'agency-pro-backstretch-set', 'BackStretchImg', array( 'src' => get_stylesheet_directory_uri() .'/images/bkgrd-softball.jpg' ) ); elseif (is_page(57) || '57' == $post->post_parent ) : wp_localize_script( 'agency-pro-backstretch-set', 'BackStretchImg', array( 'src' => get_stylesheet_directory_uri() .'/images/bkgrd-soccer.jpg' ) ); elseif (is_page(59) || '59' == $post->post_parent ) : wp_localize_script( 'agency-pro-backstretch-set', 'BackStretchImg', array( 'src' => get_stylesheet_directory_uri() .'/images/bkgrd-kickball.jpg' ) ); elseif (is_page(63) || '63' == $post->post_parent ) : wp_localize_script( 'agency-pro-backstretch-set', 'BackStretchImg', array( 'src' => get_stylesheet_directory_uri() .'/images/bkgrd-flag.jpg' ) ); elseif (is_page(55) || '55' == $post->post_parent ) : wp_localize_script( 'agency-pro-backstretch-set', 'BackStretchImg', array( 'src' => get_stylesheet_directory_uri() .'/images/bkgrd-volleyball.jpg' ) ); elseif (is_page(61) || '61' == $post->post_parent ) : wp_localize_script( 'agency-pro-backstretch-set', 'BackStretchImg', array( 'src' => get_stylesheet_directory_uri() .'/images/bkgrd-baketball.jpg' ) ); else : wp_localize_script( 'agency-pro-backstretch-set', 'BackStretchImg', array( 'src' => get_background_image() ) ); endif; }
The idea is to change Agency’s background image depending on what page is loaded. If none of the pages are loaded, it displays the default image. Half of my code works. It displays the appropriate image on the specified page (is_page()) but fails to do so when a sub page of the identified page is loaded. Any insight would be greatly appreciated.
Example of page that works: https://www.tennsports.com/softball/
Example of subpage that doesn’t (but should!): https://www.tennsports.com/softball/sample-schedule/
- The topic ‘Help With Conditional Background Image, Based on Page/Parent’ is closed to new replies.