簡體   English   中英

如何使特色圖片可點擊? - WordPress

[英]How to make featured image clickable? -Wordpress

如何讓所有特色圖片自動點擊? 由於它是 Wordpress 主題,我只能編輯 php 或添加 css。

只需將此代碼添加到主題的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 );

通常,特色圖像的功能沒有附加鏈接。 不同的主題以不同的方式使用特色圖像的功能。 例如,新的 29 主題將其用作頁面標題的背景,位於帖​​子標題后面。

所以最好做一個父主題的子主題,編輯php文件設置鏈接。 如果不編輯代碼,您將無法設置特色圖片的鏈接。

插入圖像 > 單擊要插入的所需單元格 > 在右側向下:“鏈接到” > 個性化 URL。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM