大佬帮看下,这段代码能自动为图片添加alt和title属性吗?
<blockquote>function add_image_alt_title_tags($content) {function add_image_alt_title_tags($content) {global $post;
$post_title = $post->post_title;
$pattern = '/<img(.*?)\/>/i';
preg_match_all($pattern, $content, $matches);
foreach ($matches as $index => $img_tag) {
if (strpos($img_tag, ' alt=') === false || preg_match('/ alt=["\']\s*["\']/', $img_tag)) {
$replacement = preg_replace('/<img/', '<img alt="' . $post_title . ' ' . ($index + 1) . '" title="' . $post_title . ' ' . ($index + 1) . '"', $img_tag);
$content = str_replace($img_tag, $replacement, $content);
}
}
return $content;
}
add_filter('the_content', 'add_image_alt_title_tags'); ***内容可能违规暂时被隐藏***
有插件不用,去网站找代码干啥哦
页:
[1]