WordPress代码实现自动给图片添加alt标签
因为蜘蛛并不能像人一样看出图片上到底是什么,所以图片的ALT对蜘蛛来说显得尤为重要,这点做好了也能加分。
以下代码能为图片自动添加ALT,将其加入正在使用的主题 functions.php 文件内即可:
/** Auto-Generate ALT tag for images */ function image_alt_tag($content){ global $post;preg_match_all('/<img (.*?)\/>/', $content, $images); if(!is_null($images)) {foreach($images[1] as $index => $value) { $new_img = str_replace('<img', '<img alt="'.get_the_title().'-'.get_bloginfo('name').'"', $images[0][$index]); $content = str_replace($images[0][$index], $new_img, $content);}} return $content; } add_filter('the_content', 'image_alt_tag', 99999);
《WordPress代码实现自动给图片添加alt标签》版权归逐凨所有
转载请保留原文链接:https://izhizu.com/wordpress/65.html
转载请保留原文链接:https://izhizu.com/wordpress/65.html
THE END
二维码
共有 0 条评论