內容簡介
```html
<ul>
<li>Image Alt Sync 掃描選定的文章並更新文章內包含的所有<img>標籤,該標籤引用媒體項目(類別 wp-image-###),並將其alt屬性替換為附件的_wp_attachment_image_alt值:
<ul>
<li>如果圖像在媒體庫中,它會優先選擇附件的Alt文本。</li>
<li>如果未設置附件alt,則會回退到圖像文件名(無擴展名)或文章標題(在UI中可配置)。</li>
<li>可選擇跳過在媒體庫中找不到的圖像。</li>
<li>可選擇按圖像文件擴展名限制(例如,jpg、webp)。</li>
</ul>
</li>
<li>首先進行乾跑,查看將發生的具體更改。日誌顯示已處理每個文章以及每個圖像alt的更改。</li>
<li>突出特點
<ul>
<li>按批次處理每個文章,可自定義延遲時間(默認100篇文章,1秒)。</li>
<li>按文章狀態和日期範圍篩選(快速按鈕:今天、昨天、上週、上個月、YTD、全部)。</li>
<li>驗證“日期後”≤“日期前”。</li>
<li>通過按鈕限制文章ID範圍,以自動填充最低和最高文章ID。</li>
<li>跳過沒有<img>的文章(可選)。</li>
<li>排除圖像擴展名(逗號分隔,例如.svg、.gif)。</li>
<li>乾跑(瀏覽器和WP-CLI)顯示可點擊的文章ID,文章標題,文件名和詳細的舊→新的alt替換。</li>
<li>僅處理至少有一個圖片附件的文章。</li>
</ul>
</li>
</ul>
```
### 問題與答案:
1. 什麼是Image Alt Sync插件的主要功能?
- 答:Image Alt Sync插件主要功能是掃描選定的文章並更新文章內包含的圖片標籤的alt屬性,讓其替換為附件的_wp_attachment_image_alt值。
2. 在Image Alt Sync中,如何決定替換alt屬性的優先順序?
- 答:如果圖片在媒體庫中,它會優先選擇附件的Alt文本;如果未設置附件alt,則會回退到圖像文件名(無擴展名)或文章標題。
3. 可否跳過在媒體庫中找不到的圖像?
- 答:是的,Image Alt Sync插件提供可選功能以跳過在媒體庫中找不到的圖像。
4. 如何預覽更改而不保存?
- 答:可選擇啟用乾跑模式,在不保存的情況下預覽更改。
5. 如何使用WP-CLI進行Image Alt Sync的操作?
- 答:從WordPress根目錄運行以下命令:
```
wp image-alt-sync run --status=publish --after=2025-01-01 --before=2025-08-13 --batch-size=100 --delay=1 --dry-run --low-id=1 --high-id=9999 --skip-noimg=1 --exclude-ext=".svg,.gif"
```
外掛標籤
開發者團隊
原文外掛簡介
Image Alt Sync scans selected posts and updates any tags found in the post content that reference media items (class wp-image-###), and replaces their alt attributes with the attachment’s _wp_attachment_image_alt value:
– If the image is in the Media Library, it prefers the attachment’s Alt Text.
– If no attachment alt is set, it falls back to the image filename (without extension) or the post title (configurable in the UI).
– Optionally skip images that aren’t found in the Media Library.
– Optionally restrict by image file extensions (e.g. jpg,webp).
Run in dry run first to see exactly what would change. The log shows each post processed and any per-image alt changes.
Highlights
– Processes per post in batches with a customizable delay (default 100 posts, 1s).
– Filter by post status and date range (quick buttons: Today, Yesterday, Last week, Last month, YTD, All).
– Validate that “Date after” ≤ “Date before”.
– Limit by Post ID range with buttons to auto-fill lowest and highest post IDs.
– Skip posts without (optional).
– Exclude image extensions (comma-separated, e.g. .svg,.gif).
– Dry run (browser & WP-CLI) shows clickable post IDs, post titles, filenames, and detailed old → new alt replacements.
– Only processes posts that have at least one image attachment.
For more details you can send mail with your suggestions, recommendation to [email protected]
Usage
Choose your filters (date range, min/max post ID, or “Apply to all posts”).
Set Batch size and optional Delay between batches to throttle load.
Choose a Date Range, or click a shortcut button (autofills Date after/Date before).
(Optional) Enter Lowest/Highest Post ID or click the quick-fill buttons.
(Optional) Check Skip posts without .
(Optional) Enter Exclude extensions like .svg,.gif.
Optionally enable Dry run to preview changes without saving.
Click Start. Progress and detailed per-post changes appear in the log.
If needed, click Stop to pause after the current batch finishes.
Tips
– Use the “Lowest ID” and “Highest ID” buttons to auto-fill the ID range.
– Use the extension filter (e.g. jpg, jpeg, png, webp) to target specific image types.
– Check “Skip images not in media library” to avoid external or missing files.
Usage (WP-CLI)
From your WordPress root:
wp image-alt-sync run --status=publish --after=2025-01-01 --before=2025-08-13 --batch-size=100 --delay=1 --dry-run --low-id=1 --high-id=9999 --skip-noimg=1 --exclude-ext=".svg,.gif"
Args
– --status= publish|pending|draft|any (default: publish)
– --after= YYYY-MM-DD (optional)
– --before= YYYY-MM-DD (optional)
– --batch-size= integer (default: 100)
– --delay= seconds (float, default: 1)
– --dry-run flag (no changes saved if provided)
– --low-id= minimum post ID (optional)
– --high-id= maximum post ID (optional)
– --skip-noimg= 1|0 (default 0)
– --exclude-ext= comma-separated list like .svg,.gif
Credits
Crafted with ❤️ for accessible content.
