我想删除所有页面面包屑中指向产品存档的链接。
为此,我在 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?但我不知道如何检查。
慕田峪4524236
幕布斯6054654