如何使特色图片可点击? -WordPress

时间:2019-06-14 06:53:46

标签: php html wordpress

如何使所有精选图片自动点击?因为它是Wordpress主题,所以我只能编辑php或添加CSS。

3 个答案:

答案 0 :(得分:1)

只需将此代码添加到主题的functions.php文件中即可。

此代码仅在生成的代码周围添加一个链接,以在您的网站上显示特色图像或发布缩略图。

function wpb_autolink_featured_images( $html, $post_id, $post_image_id ) {
    $html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_the_title( $post_id ) ) . '">' . $html . '</a>';
    return $html;
    }
    add_filter( 'post_thumbnail_html', 'wpb_autolink_featured_images', 10, 3 );

此代码还将在单个帖子页面上添加围绕特色图片的链接。如果您不想将单个帖子中的特色图片链接到同一帖子,请使用此代码。

function wpb_autolink_featured_images( $html, $post_id, $post_image_id ) {

If (! is_singular()) { 

$html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_the_title( $post_id ) ) . '">' . $html . '</a>';
return $html;

} else { 

return $html;

}

}
add_filter( 'post_thumbnail_html', 'wpb_autolink_featured_images', 10, 3 );

答案 1 :(得分:0)

通常,特色图片的功能没有链接。不同的主题使用特色图像的功能有所不同。例如,新的“二十十九”主题将其用作帖子标题后面页面标题的背景。

因此,最好将父主题设为子主题,然后编辑php文件以设置链接。如果不编辑代码,则无法设置特色图片的链接。

答案 2 :(得分:0)

插入图像>单击要插入它的所需单元格>右下方:“链接到”>个性化URL。

相关问题