WordPress主题不通过图片的标题文本


WordPress theme not pulling through title text of images

我正试图使我使用的主题(DICE)通过图像的标题文本拉。

我使用的代码如下;

if ( has_post_thumbnail() ) {
if ( $linking == 'lightbox' ) {
    $alt = esc_attr(get_the_title( $post->ID ) );
    $the_title = esc_attr(get_the_title( $post->ID ) );
    $img = get_the_post_thumbnail( $post->ID, $size, array( 'alt' => $alt, 'title' => $the_title ) ); 
}
else
        $img = get_the_post_thumbnail( $post->ID, $size );
}
elseif( $placeholder ) {
    $img = btp_render_placeholder( $size, '', false );
}
else {
    return;
}

我添加的唯一一行是

$the_title = esc_attr(get_the_title( $post->ID ) ); 

'title' => $the_title 

也在数组中。所有的文本是拉通过很好,所以我不确定为什么标题文本没有拉通过?

任何帮助都是感激的。谢谢。

使用两个独立的变量来获得相同的信息是糟糕的编程实践。尽量只使用一个变量,像这样:

if ( $linking == 'lightbox' ) {
    $post_title = esc_attr(get_the_title( $post->ID ) );
    //The Image
    $img = get_the_post_thumbnail( $post->ID, $size, array( 'alt' => $post_title, 'title' => $post_title ) ); 
}