我想刪除所有頁面面包屑中指向產品存檔的鏈接。為此,我在 Yoast 文檔中找到了解決方案。除了產品頁面外,它運行良好。這是我當前的代碼:/* Remove "Products" from Yoast SEO breadcrumbs in WooCommerce */add_filter( 'wpseo_breadcrumb_links', function( $links ) { // Check if we're on a WooCommerce page // Checks if key 'ptarchive' is set // Checks if 'product' is the value of the key 'ptarchive', in position 1 in the links array if ( is_woocommerce() && isset( $links[1]['ptarchive'] ) && 'product' === $links[1]['ptarchive'] ) { // True, remove 'Products' archive from breadcrumb links unset( $links[1] ); // Added by me to remove it on product single pages - doesn't work! } elseif ( is_product() && isset( $links[1]['ptarchive'] ) && 'product' === $links[1]['ptarchive'] ) { // True, remove 'Products' archive from breadcrumb links unset( $links[1] ); } // Rebase array keys $links = array_values( $links ); // Return modified array return $links;});它會刪除存檔頁面和所有其他 WooCommerce 頁面上的鏈接,正如您通過條件標記所期望的那樣is_woocommerce()。但由于某種原因,它無法在單個產品頁面上運行。正如您所看到的,我添加了一項額外的檢查,檢查我是否位于帶有 的產品頁面上is_product()。不幸的是,這不起作用。也is_singular('proudct')別擔心。也許陣列有問題$links?但我不知道如何檢查。
2 回答

慕田峪4524236
TA貢獻1875條經驗 獲得超5個贊
您還可以通過添加“||”來刪除商店頁面上的“商店”或“產品”鏈接。is_archive() ' 到 if 條件如下:
if ( is_product() || is_archive() ) {
// True, remove 'Products' archive from breadcrumb links
unset( $links[1] );
}

幕布斯6054654
TA貢獻1876條經驗 獲得超7個贊
我將 if 條件更改為:
if ( is_product() ) { // True, remove 'Products' archive from breadcrumb links unset( $links[1] ); }
現在可以了。其他頁面以前可以使用,但沒有該功能。
- 2 回答
- 0 關注
- 158 瀏覽
添加回答
舉報
0/150
提交
取消