wordpress给文章图片自动添加alt和title信息

functions.php里面添加:
add_filter('the_content', 'imagesalt');
function imagesalt($content) {
       global $post;
       $pattern ="/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
       $replacement = '<a$1href=$2$3.$4$5 alt="'.$post->post_title.'" title="'.$post->post_title.'"$6>';
       $content = preg_replace($pattern, $replacement, $content);
       return $content;
}
站长推荐:♥紫苏淘免费领取大额优惠券
© 版权声明
THE END
打赏一下吧:1分不嫌少9.9不嫌多,谢谢支持
点赞0赞赏
分享
评论 抢沙发