之前的主题是首图自动显示在封面上,换了个主题不支持首图显示封面,有什么插件可以批量设置首图是封面的吗
香港网友:这个俺也不晓得
黑龙江网友:加到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’);
复制代码
江苏网友:我是抓第一个img的,用那个wpjam啥的
甘肃网友:
tl3821 发表于 2020-12-29 21:24
我是抓第一个img的,用那个wpjam啥的
是安装这个插件吗,我的因为是用的图床,各种方案试了都不行
河南网友:
glisten 发表于 2020-12-29 22:25
是安装这个插件吗,我的因为是用的图床,各种方案试了都不行
对 理论上 只要你那个 标签是 img 的就行了
不然就用楼上那个代码的
宁夏网友:
tl3821 发表于 2020-12-29 22:53
对 理论上 只要你那个 标签是 img 的就行了
不然就用楼上那个代码的
抓第一个img是设置自定义字段吗,具体怎么设置的