Automatically Setting the First Image in WordPress Articles as Featured Image

45 views Asked by At

I'm using WordPress version 6.4.1 with the twentytwentyfour theme. The images are hosted externally。 Is there a way to achieve this through custom code? I'm open to using functions.php or any other recommended method. Could someone provide guidance or code snippets on how to implement this functionality?

$thumbnail_url = get_post_meta(get_the_ID(), 'thumbnail_url', true);
if ($thumbnail_url) {
    echo '<img src="' . esc_url($thumbnail_url) . '" alt="Custom Thumbnail">';
}

i don't know where to place the code to retrieve and display this custom thumbnail.

0

There are 0 answers