Customising PHP for WordPress post header image

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?


<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(); ?>" />

PHP file

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    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(); ?>

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

<?php else : ?>

Read more here: Customising PHP for WordPress post header image

Leave a Reply

Your email address will not be published. Required fields are marked *