如何使用 Yoast SEO 插件在站點地圖中添加額外的鏈接
打開您的站點當前 wp 主題(子)文件 functions.php 並添加下一個代碼:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | add_filter('wpseo_sitemap_index', function () { $links = [ 'https://mysite.com/link1', 'https://mysite.com/link2', 'https://mysite.com/link3', 'https://mysite.com/link4', 'https://mysite.com/link5' ]; //also you can generate links by your own business logic $appended_text = ''; foreach ($links as $l) { $appended_text .= "<sitemap><loc>{$l}</loc></sitemap>"; } return $appended_text; }); |
在數組 $links 中設置您想要添加到站點地圖的鏈接。 如果您是開發人員,您可以添加自己的邏輯來生成鏈接。 另請閱讀 WooCommerce 產品過濾器模塊“SEO URL 請求”