如何添加特色图片Alt标签

时间:2020-09-26 21:12:04

标签: wordpress image

我想将主题上的第一张图片设置为特色视觉。

我将这些代码添加到content.php。

<?php if ( has_post_thumbnail() ) {
the_post_thumbnail(‘large’);
} else {
echo ‘<img src=”‘;
echo catch_that_image();
echo ‘” alt=”” />’;
} ?>

我将这些代码添加到function.php

function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
if(preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches)){
$first_img = $matches [1] [0];
return $first_img;
}
else {
$first_img = get_template_directory_uri()."/images/default.jpg";
return $first_img;
}
}

但是有问题。没有图片alt标签。

我该如何解决?

我的网页:https://www.ceofix.net/

0 个答案:

没有答案
相关问题