Php Wordpress,相关帖子如何将ALT标签添加到img?
因此,我有一个函数可以在我的functions.php for Wordpress中获取相关帖子。它工作正常,但图像没有alt标记 我的部分代码:Php Wordpress,相关帖子如何将ALT标签添加到img?,php,wordpress,Php,Wordpress,因此,我有一个函数可以在我的functions.php for Wordpress中获取相关帖子。它工作正常,但图像没有alt标记 我的部分代码: $img = genesis_get_image() ? genesis_get_image( array( 'size' => 'related' ) ) : '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/related.png" alt="' . g
$img = genesis_get_image() ? genesis_get_image( array( 'size' => 'related' ) ) : '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/related.png" alt="' . get_the_title() . '" />';
$related .= '<li><a href="' . get_permalink() . '" rel="bookmark" title="' . get_the_title() . '">' . $img . '<p>' . get_the_title() . '</p></a></li>';
$img=genesis\u get\u image()?genesis_get_图像(数组('size'=>'related')):'';
$related.='';
你知道我如何告诉Wordpress将标题添加为alt标记,就像链接中的标题标记一样吗
谢谢尝试将POST | PAGE ID作为获取_title()参数 在循环内部,single.php或page.php:
get_the_title( get_the_ID() );
外部循环:您需要在之前获取post ID
$post_id = X (there are many ways to get the ID);
get_the_title( $post_id );
为了帮助您获取帖子ID,我想了解更多关于您的文件的信息
文件是什么?单个、页面、类别(内部循环).因此我找到了解决方案。我不知道这是因为我使用的Genesis框架的缘故,还是因为这是一个通用的Wordpress 然而,通过将attr添加到genesis_get_图像数组中,它就完成了
'attr' => array ('alt' => 'Related Image')