Wood Chen

Display a Featured Image in the Right Sidebar in WordPress

0 comments57 views90 words

This post was translated from Chinese by AI. If anything reads oddly, the Chinese original is authoritative. 中文原文

  1. Install the Enhanced Text Widget plugin, which lets you use php code in widget areas

  2. Code:

    
    

PS: Getting the featured image URL on a WordPress post page

Getting a featured image URL in WordPress mainly requires two functions: get_post_thumbnail_id and wp_get_attachment_image_src. Below are the methods for getting image URLs in thumbnail, medium, large, full, and custom sizes

  • Get the featured image: thumbnail
ID), 'thumbnail');
echo $thumbnail_image_url[0];
?>
  • Get the featured image: medium
ID), 'medium');
echo $medium_image_url[0];
?>
  • Get the featured image: large
ID), 'large');
echo $large_image_url[0];
?>
  • Get the featured image: full
ID), 'full');
echo $full_image_url[0];
?>
  • Get the featured image: custom 100x100
ID), array(100,100));
echo $array_image_url[0];
?>

Last updated 2024-01-14

Related posts

Comments 0