glisten大佬:
之前的主题是首图自动显示在封面上,换了个主题不支持首图显示封面,有什么插件可以批量设置首图是封面的吗
嗷嗷大佬:
这个俺也不晓得
流河旱树大佬:
加到functions.php文件里
- // Auto add featured image
- function wpsites_auto_set_featured_image() {
- global $post;
- $featured_image_exists = has_post_thumbnail($post->ID);
- if (!$featured_image_exists) {
- $attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
- if ($attached_image) {
- foreach ($attached_image as $attachment_id => $attachment) {set_post_thumbnail($post->ID, $attachment_id);}
- }
- }
- }
- add_action(‘the_post’, ‘wpsites_auto_set_featured_image’);