批量给WordPress没有图片的文章自动配图提高内容优化

从内容的编辑用户体验和搜索引擎SEO体验度上,是不是如果有图文的内容更容易被接受。但是有些文章我们可能没有图片,是否有办法批量添加图片呢?用什么办法可以批量给WordPress文章没有图片的批量插入图片,提高SEO效果。

图片[1]-批量给WordPress没有图片的文章自动配图提高内容优化-WordPress建站笔记
// 批量添加图片给没有图片的文章 By:https://www.cnwper.com/add-nothumb.html
if (!is_page()) {
        global $post;
        $temp_url = "";
        if (!has_post_thumbnail()) {
            $id      = $post->ID;
            preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER);
            $n = count($strResult[1]);
            if ($n <= 0) {
                $temp_no                 = rand(1, 51);
                $temp_url                = "<center><p><img src='" . get_bloginfo('url') . "/images/" . $temp_no . ".jpg' alt='" . $post->post_title . "'></p></center>";
                $content                 = $temp_url . $content;
                $my_post                 = array();
                $my_post['ID']           = $id;
                $my_post['post_content'] = $content;
                wp_update_post($my_post);
            }
        }
    }
    return $content;
}

我们可以提前给images目录中添加一些图片。比如1.jpg、2.jpg、…..100.jpg

这样可以随机调用图片插入到无图内容的WP网站中。

1.1/5 - (60 votes)
© 版权声明
THE END
喜欢就支持一下吧
点赞6 分享