我正试图在我的博客上添加alt属性来发布缩略图。
我让alt文本回显,但不是作为属性,而是作为文本!
<?php if ( has_post_thumbnail() ) {$image_src = wp_get_attachment_image_src( get_post_thumbnail_id(),’thumbnail’ ); $image_alt = wpseoFocusKW();
echo '<img width="100%" src="' . $image_src[0] . '" alt=' . $image_alt .' >';} ?></div></div> 您可以在这里看到问题:http://benefacto.org/three-days-paid-volunteering-leave-an-update-from-rob-wilsons-office/
您会注意到,我使用了Yoast关键字作为alt,这很好。
任何想法都很感激。
本
发布于 2016-02-12 11:50:15
尝试以下操作(仅限于PHP部分):
<?php
if (has_post_thumbnail()) {
$image_src = wp_get_attachment_image_src(get_post_thumbnail_id(),'thumbnail');
$image_alt = wpseo_get_value('focuskw', $post->ID);
echo '<img width="100%" src="'.$image_src[0].'" alt="'.$image_alt.'">';
}
?>函数wpseoFocusKW()的内容如下所示:
function wpseoFocusKW()
{
$focuskw = wpseo_get_value('focuskw', $post->ID);
echo $focuskw;
}此函数只回显关键字,但不返回! 参考: http://snipplr.com/view/67931/
您可以创建一个自定义函数或更改原始,如下所示:
function wpCustomSeoFocusKW($return = false)
{
$focuskw = wpseo_get_value('focuskw', $post->ID);
if ($return) {
return $focuskw;
} else {
echo $focuskw;
}
}https://stackoverflow.com/questions/35361463
复制相似问题