get featured image post wordpress by post id

Use the following code to get the featured image of a WordPress post by post ID:

$post_id = 123; // Replace with your post ID
$image_url = wp_get_attachment_image_url( get_post_thumbnail_id( $post_id ), 'full' );
echo $image_url;

Explanation: 1. Set the variable $post_id to the ID of the post for which you want to retrieve the featured image. 2. Use get_post_thumbnail_id( $post_id ) to get the ID of the featured image attached to the specified post. 3. Use wp_get_attachment_image_url() to retrieve the URL of the featured image with the specified image size (in this example, 'full'). 4. Output the image URL using echo $image_url.