[resolved] [Theme: Catchbox] Dynamic headers/featured image as header (2 posts)

  1. hrcwebmaster
    Posted 3 years ago #

    Hi there,
    I would like to "switch" my header for different pages I have in my Web site. Since this would apply to about 50 different pages, I was hoping to use either the featured image or custom fields to "switch" from my default header to the image of my choosing. I would appreciate any advice and code! I'm very new to WordPress and PHP, but catching on quickly!

  2. hrcwebmaster
    Posted 3 years ago #

    Ok I figured it out. In header.php I added this code:

    // Check to see if the header image has been removed
    if (get_post_meta( $post->ID, 'custom-field', true )) : ?>
    <h1 id="site-logo">
    <a href="
    <?php echo esc_url( home_url( '/' ) ); ?>" title="
    <?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home">
    <img src="<?php echo get_post_meta( $post->ID, 'custom-field', true ); ?>" />
    <?php else : ?> 
    <img src="<?php header_image(); ?>" />
    <?php endif; ?>

    You just need to replace custom-field with the name of your custom field.

Topic Closed

This topic has been closed to new replies.

About this Topic