亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

WooCommerce:從 Yoast 面包屑中刪除“產品”檔案

WooCommerce:從 Yoast 面包屑中刪除“產品”檔案

PHP
哆啦的時光機 2023-09-15 17:21:37
我想刪除所有頁面面包屑中指向產品存檔的鏈接。為此,我在 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] );

}


查看完整回答
反對 回復 2023-09-15
?
幕布斯6054654

TA貢獻1876條經驗 獲得超7個贊

我將 if 條件更改為:

if ( is_product() ) {
    // True, remove 'Products' archive from breadcrumb links
    unset( $links[1] );
}

現在可以了。其他頁面以前可以使用,但沒有該功能。


查看完整回答
反對 回復 2023-09-15
  • 2 回答
  • 0 關注
  • 158 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號