为了账号安全,请及时绑定邮箱和手机立即绑定

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 关注
  • 72 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信