admin管理员组文章数量:1327975
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
1 Answer
Reset to default 2Create "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 directoryget_template_directory_uri()
: url path to parent Theme directory
本文标签: post thumbnailsShow a default image
版权声明:本文标题:post thumbnails - Show a default image 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742252701a2441058.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论