如何从面包屑中删除商店文本?[首页-->购物-->粉色喜马拉雅盐]
我想根据我在M WordPress站点中的导航菜单设置面包屑。[主页-->产品-->盐-->粉色喜马拉雅盐]
我用了一些网页,自定义链接,分类和产品到我的主菜单。
见截图。
Bredcrumb -
菜单-
最佳答案
您可以通过主题覆盖woomerce模板(请阅读以下官方文档):
Template Structure + Overriding Templates via a Theme
从plugins/woocommerce/templates/global/breadcrumb.php
复制文件后
若要:themes/yourtheme/woocommerce/global/breadcrumb.php
,您可以使用以下内容替换代码:
<?php
/**
* Shop breadcrumb
*
* This template can be overridden by copying it to yourtheme/woocommerce/global/breadcrumb.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.3.0
* @see woocommerce_breadcrumb()
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! empty( $breadcrumb ) ) {
$breadcrumb0 = $breadcrumb[0];
$shop_txt = __( 'Shop', 'woocommerce' );
$products_txt = __( 'Products', 'woocommerce' );
$products_url = home_url( '/products/' );
$breadcrumb10 = array( $products_txt );
$breadcrumb11 = array( $products_txt, $products_url );
if(is_product() || is_shop() || is_product_category() || is_product_tag() ){
if( $breadcrumb[1][0] == $shop_txt ){
if( ! empty( $breadcrumb[1][1] ) )
$breadcrumb[1] = $breadcrumb11;
else
$breadcrumb[1] = $breadcrumb10;
} else {
unset($breadcrumb[0]);
array_unshift($breadcrumb, $breadcrumb0, $breadcrumb11);
}
}
echo $wrap_before;
foreach ( $breadcrumb as $key => $crumb ) {
echo $before;
if ( ! empty( $crumb[1] ) && sizeof( $breadcrumb ) !== $key + 1 ) {
echo '<a href="' . esc_url( $crumb[1] ) . '">' . esc_html( $crumb[0] ) . '</a>';
} else {
echo esc_html( $crumb[0] );
}
echo $after;
if ( sizeof( $breadcrumb ) !== $key + 1 ) {
echo $delimiter;
}
}
echo $wrap_after;
}
这将:
用“产品”代替“商店”
当“商店”不存在时,在“家”后面加上“产品”。
因此,你的面包屑将始终以:
Home > Products
开始在商店,档案和单一产品页面…