我想刪除所有頁面面包屑中指向產(chǎn)品存檔的鏈接。為此,我在 Yoast 文檔中找到了解決方案。除了產(chǎn)品頁面外,它運(yùn)行良好。這是我當(dāng)前的代碼:/* 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 頁面上的鏈接,正如您通過條件標(biāo)記所期望的那樣is_woocommerce()。但由于某種原因,它無法在單個(gè)產(chǎn)品頁面上運(yùn)行。正如您所看到的,我添加了一項(xiàng)額外的檢查,檢查我是否位于帶有 的產(chǎn)品頁面上is_product()。不幸的是,這不起作用。也is_singular('proudct')別擔(dān)心。也許陣列有問題$links?但我不知道如何檢查。
WooCommerce:從 Yoast 面包屑中刪除“產(chǎn)品”檔案
哆啦的時(shí)光機(jī)
2023-09-15 17:21:37