如果未定义,如何将wordpress文章标题设置为图像alt?
我在帖子内容中有很多图片,大多数都没有alt值。 是否有任何函数可以将文章标题设置为image alt。 我尝试了这个功能,但它不起作用如果未定义,如何将wordpress文章标题设置为图像alt?,wordpress,Wordpress,我在帖子内容中有很多图片,大多数都没有alt值。 是否有任何函数可以将文章标题设置为image alt。 我尝试了这个功能,但它不起作用 function add_alt_tags($content) { global $post; preg_match_all('/<img (.*?)\/>/', $content, $images); if(!is_null($images)) { f
function add_alt_tags($content)
{
global $post;
preg_match_all('/<img (.*?)\/>/', $content, $images);
if(!is_null($images))
{
foreach($images[1] as $index => $value)
{
if(!preg_match('/alt=/', $value))
{
$new_img = str_replace('<img', '<img alt="'.get_the_title().'"', $images[0][$index]);
$content = str_replace($images[0][$index], $new_img, $content);
}
}
}
return $content;
}
add_filter('the_content', 'add_alt_tags', 99999);
函数添加标签($content)
{
全球$员额;
preg_match_all(“//”,$content,$images);
如果(!为null($images))
{
foreach($images[1]作为$index=>$value)
{
如果(!preg_match('/alt=/',$value))
{
$new\u img=str\u replace('