[WordPress] 外掛分享: Hide featured image on all single page/post

首頁外掛目錄 › Hide featured image on all single page/post
5,000+
安裝啟用
★★★★
4.6/5 分(14 則評價)
1503 天前
最後更新
問題解決
WordPress 4.6+ PHP 7.2+ v1.0 上架:2020-12-31

內容簡介

這個輕巧的外掛在瀏覽單獨的頁面和文章時隱藏所有的特色圖片。文章不會被修改—如果你已選擇了特色圖片,它仍然存在。這個外掛只是禁用佈景主題渲染頁面時訪問圖片的能力。如果你的佈景主題在搜尋結果、文章頁、分類列表等顯示特色圖片,它仍然可以這樣做。搜尋引擎和社交媒體平台尋找一個伴隨摘要的圖片時,也仍然可以在文章元數據中找到特色圖片的URL。

此外掛沒有設置,只會執行一項功能。

更改會套用於現有的文章,以及在活動後創建的所有文章。你需要編輯任何受此更改影響的舊文章(如果你想顯示特色圖片,你需要將其插入到內容中)。如果你有很多舊內容,你可能需要使用其他外掛,例如在單頁和文章上條件顯示特色圖像,它僅影響新文章。

技術註解

佈景主題通過直接在數據庫中查找數據而不是調用get_the_post_thumbnail()或wp_get_attachment_image()找到特色圖片的,仍然可能在此外掛情況下發出特色圖片的HTML。作為第二道防線,此外掛加載了一個樣式表,如果在HTML中發現圖片,會試圖隱藏它。如果佈景主題使用了不尋常的實體和類名,這也可能失敗。自定義CSS規則應當始終可以作為備用方案(在這種情況下,就不需要使用此外掛了)。

這個外掛還無意中阻止了特色圖片在你插入的「文章特色圖片」區塊中出現。我正在研究是否可能檢測到預設顯示和後來有意插入特色圖片之間的區別。與此同時,作為解決方法,不要使用「文章特色圖片」區塊,而要插入一個「圖片」區塊,從媒體庫中重新選擇圖像(我更喜歡這種方式,因為它可以更好地控制大小、alt文本等)。

如果你發現某個佈景主題對此外掛不起作用,請告訴我。

捐贈

作者並不是在為自己募款。如果您覺得此外掛有用並想要回報,請考慮捐贈給直接幫助有需要的人的組織。

外掛標籤

開發者團隊

⬇ 下載最新版 (v1.0) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Hide featured image on all single page/post」→ 直接安裝(推薦)

原文外掛簡介

This lightweight plugin hides all featured images on pages and posts when they are viewed in their own tab. The posts are not modified — they still have a featured image if you selected one. The plugin only disables the theme’s ability to access the image when rendering the page. If your theme displays featured images in search results, Posts page, category lists, and so on, it still can do that. Social media platforms and search engines that look for an image to accompany the excerpt, can also still find the featured image URL in the post metadata.
There are no settings; the plugin just does the one thing.
The change applies to existing posts as well as anything you create after activation. You would need to edit any old posts that are adversely affected by this change (if you want the featured image to display, you would have to insert it into the content). If you have a lot of old content, you might want to use a different plugin such as Conditionally display featured image on singular pages and posts, which by default only affects new posts.
TECHNICAL NOTE
Themes that find the featured image by looking up data in the database directly as opposed to calling get_the_post_thumbnail() or wp_get_attachment_image(), may still emit HTML for the featured image despite this plugin. As a second line of defense, the plugin loads a stylesheet that tries to hide the image if it is present in the HTML. This also might fail if the theme has used unusual entities and class names. Custom CSS rules should always be possible as a fallback (in which case you don’t need this plugin).
This plugin also (not on purpose) blocks the featured image from appearing in the content where you’ve inserted a “Post featured image” block. I’m looking into whether it might be possible to detect the difference between a request for the featured image for default display versus a deliberate insertion later. In the meantime, as a workaround, don’t use the “Post featured image” block, but instead insert an “Image” block and re-select the image from your media library (I prefer that anyway since it gives more control over size, alt text, etc).
If you find a theme this doesn’t work with, please let me know.
Donations
The author is not soliciting donations for himself. If you find this useful and want to pay it forward, please consider donating to an organization that directly helps people in need.

延伸相關外掛

文章
Filter
Apply Filters
Mastodon