php – 从WooCommerce的BreadCrumb中删除“Shop”
作者:互联网
如何从woo商务中的面包屑中删除商店文字?[首页 – >商店 – > Pink Himalayan Salt]
我想根据我在WordPress网站上的导航菜单设置面包屑.[主页 – >产品 – >盐 – >粉红色喜马拉雅盐]
我使用了一些页面,自定义链接,类别&产品到我的主菜单.
见截图.
解决方法:
您可以通过主题覆盖WooCommerce模板(请阅读以下官方文档):
Template Structure + Overriding Templates via a Theme
从plugins / woocommerce / templates / global / breadcrumb.php复制文件后
to: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;
}
这将:
>用“产品”替换“商店”
>当“Shop”未退出时,在“Home”之后添加“Products”.
So your breadcrumps will always start with:
Home > Products
on shop, archives and single product pages…
标签:wordpress,php,woocommerce,breadcrumbs 来源: https://codeday.me/bug/20190701/1349077.html