php - 空 alt 标签 wordpress

标签 php css wordpress alt

我将 WordPress 与 Listingpro 模板一起使用,我一直在寻找解决方案并找到了以下内容:

// An attachment/image ID is all that's needed to retrieve its alt and title attributes.
$image_id = get_post_thumbnail_id();    
$image_alt = get_post_meta($image_id, '_wp_attachment_image_alt', TRUE);  
$image_title = get_the_title($image_id);

但是,当我添加这个 alt='$image_alt' 时,显示了一个空的 alt。

最佳答案

<img src="whatever-src" alt="'.$image_alt.'">

当它在 echo 中时,这就是您所需要的。 仅当有与该图像相关联的任何 alt 时。

关于php - 空 alt 标签 wordpress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59473891/

相关文章:

PHP-PSR-4 : Autoloader (composer) and multiple namespaces with the same root

css - SVG 过滤器使元素在 Safari 和移动版 Chrome 中不可见

html - 需要在内联元素之间插入空格

jquery - 使用文本框将 Bootstrap 下拉菜单调整为内容宽度

javascript - 嵌入的 YouTube 视频会降低网络速度

php - PHP 上的类实例?

javascript - 无法从数据库打印答案

php - 使用 PHP 仅显示数据库中的一项

wordpress - .htaccess 重定向过多。将除 ip 之外的所有用户重定向到网站的不同部分

html - 带有 CustomizR 主题的全宽 DIV