Search code examples
wordpresstaxonomy

How do I use the featured image of another page in a post in WordPress?


I have a taxonomy page taxonomoy-$slug.php and I want to be able to display the featured image of another page on it. Is there any way to do this without plugins?


Solution

  • You have to place your page ID static into a variable, just like the below code:

    <?php 
    $post_id = 12;      //place here your page id  
    $post_thumbnail_id = get_post_thumbnail_id( $post_id ); 
    $image = wp_get_attachment_image_src( $post_thumbnail_id ); ?>
    

    Now, place this $image variable inside the tag:

    <img src="<?php echo $image[0]; ?>" />
    

    I hope, this may be helpful to you.