如何在wordpress中检索和显示图像的替代文字?试图用标题代替 alt。这是原始代码。
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
Run Code Online (Sandbox Code Playgroud)
所以在 h1 我想要:
<h1 class="entry-title">"alt text of image"</h1>
Run Code Online (Sandbox Code Playgroud)
试着把它放在一个像这样的变量中:
$alt_text = get_post_meta($img_id , '_wp_attachment_image_alt', true);
<h1 class="entry-title"><?php echo $alt_text; ?></h1>
Run Code Online (Sandbox Code Playgroud)
但它没有出现。任何解决方案?