I’m seeking help to best customise the below script. Instead of retrieving the featured image as the default header image of a single (WordPress) post, I would like the header image to be my own choosing. I want to upload an image to media library, and retrieve that. I’d like to add a custom field called headerimg and add EXAMPLE.jpg.

Could I do this something like this instead?

ALTERNATIVE

<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<img src="/uploads/<?php echo get_post_meta($post->ID, 'headerimg', true); ?>" alt="Icon for Post #<?php the_ID(); ?>" />
</a>

PHP file

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php
    if ( has_post_thumbnail() && ! post_password_required() ) :
        $featuredimage = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), 'resonar-large' );
?>
    <div class="entry-header-background" style="background-image:url(<?php echo esc_url( $featuredimage[0] ); ?>)">
        <div class="entry-header-wrapper">
            <header id="entry-header" class="entry-header">
                <div class="entry-header-inner">
                    <div class="entry-date">
                        <?php resonar_entry_date(); ?>
                    </div>

                    <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
                </div>

            </header>
        </div>
    </div>
<?php else : ?>

Read more here: Customising PHP for WordPress post header image


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: