post thumbnails - Show a default image

Hello how can I do with this function if there is no post thumbnail loaded, show a default imageecho get_the_post_thumbn

Hello how can I do with this function if there is no post thumbnail loaded, show a default image

    echo get_the_post_thumbnail( $page->ID, 'image' );          

Hello how can I do with this function if there is no post thumbnail loaded, show a default image

    echo get_the_post_thumbnail( $page->ID, 'image' );          
Share Improve this question edited Jul 18, 2020 at 5:42 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Jul 18, 2020 at 4:47 StymarkStymark 372 bronze badges 1
  • 1 Does this answer your question? Fallback default image when there is no featured image – Michael Commented Jul 18, 2020 at 15:40
Add a comment  | 

1 Answer 1

Reset to default 2

Create "images" folder in current active theme the put "default-image.jpg" in that folder.

<?php  
if ( has_post_thumbnail( ) ) {
  echo get_the_post_thumbnail( $page->ID, 'image' );
} else { ?>
<img src="<?php echo get_template_directory_uri().'/images/default-image.jpg'; ?>"/>
<?php } ?>

Use path according to the theme (parent or child).

  • get_stylesheet_directory_uri(): url path to current Theme directory

  • get_template_directory_uri(): url path to parent Theme directory

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742252702a4409451.html

相关推荐

  • post thumbnails - Show a default image

    Hello how can I do with this function if there is no post thumbnail loaded, show a default imageecho get_the_post_thumbn

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信