• Is it possible to dynamically change the header image based on the page that is selected by the viewer?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Theme Author ronangelo

    (@ronangelo)

    Sure. If for example you want the header image to be the post’s Featured Image,
    something like this should work.

    add_action( 'wp_head', 'add_header_bg_css', 999 );
    
    function add_header_bg_css() {
    
    	if ( !has_post_thumbnail() ) return;
    
    	$img = get_the_post_thumbnail( get_the_ID() );
    
    	echo '<style>#header { background-image: url(\'' . $img . '\'); }</style>';
    }
    Thread Starter Glennf

    (@glennf)

    Thanks so much. What code would be used to change the header image when a person navigates to a certain wordpress page?

    What files do you add that action and function to?

    -Glenn

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Dynamically Change Header Image?’ is closed to new replies.