如何从woo commerce中的面包屑中删除 Shop 文本?[首页 - >商店 - >粉红色喜马拉雅盐]我想根据我的WordPress网站中的导航菜单设置面包屑 . [首页 - >产品 - >盐 - >粉红色喜马拉雅盐]我在我的主菜单中使用了一些页面,自定义链接,类别和产品 .
见截图 .
Bredcrumb -
菜单 -
您可以通过主题覆盖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" by "Products"
在"Home"之后添加"Products"时"Shop"未退出 .
因此,您的面包将始终以:首页>商店,档案和单品页面上的产品......
这可以通过CSS解决,但除非您发布到您的商店的链接,否则无法解决 . 试试这样:
将此行添加到您的自定义CSS
ul.breadcrumbs li:nth-of-type(2) {display:none}
如果它不起作用,可能还需要!重要
ul.breadcrumbs li:nth-of-type(2) {display:none!important}
我无法评论这就是我必须回答的原因 . 请提供您网站的链接 . 我会用精确的CSS更新我的答案 .
我通过对functions.php https://www.screencast.com/t/U42lqPduY707进行更改得到了答案 .
if (get_post_type() == 'product') { echo sprintf($link, '#', esc_html__('Products', 'thegem')); //echo sprintf($link, get_permalink(get_option ('woocommerce_shop_page_id' , 0 )), esc_html__('Product', 'thegem')); $taxonomy = 'product_cat'; $terms = get_the_terms( $post->ID, $taxonomy ); foreach ( $terms as $c ) { $c->term_id; // echo '<a href="' . get_term_link($c, 'product_cat') . '">' . ($c->name ) . '</a>'; if($c->term_id=='36') { echo $delimiter; echo sprintf($link, get_permalink( 106 ), esc_html__($c->name, 'thegem')); } } } else { $slug = $post_type->rewrite; printf($link, $home_link . '/' . $slug['slug'] . '/', $post_type->labels->singular_name); }
灵感来自LoicTheAztec,这里有一个类似但略有不同的解决方案 . 假设您只想完全删除Shop链接:
复制文件: plugins/woocommerce/templates/global/breadcrumb.php
至: themes/yourtheme/woocommerce/global/breadcrumb.php
在新文件中,查找该行
foreach ( $breadcrumb as $key => $crumb ) {
然后在该行之后添加以下行:
if (trim(strip_tags($crumb[0])) == 'Shop') { continue; }
所以最终的代码看起来像这样:
if ( ! defined( 'ABSPATH' ) ) { exit; } if ( ! empty( $breadcrumb ) ) { echo $wrap_before; foreach ( $breadcrumb as $key => $crumb ) { if (trim(strip_tags($crumb[0])) == 'Shop') { continue; } 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; }
4 回答
您可以通过主题覆盖WooCommerce模板(请阅读以下官方文档):
Template Structure + Overriding Templates via a Theme
从 plugins/woocommerce/templates/global/breadcrumb.php 复制文件后
to: themes/yourtheme/woocommerce/global/breadcrumb.php ,您可以通过将其替换为以下代码来更改代码:
这将:
替换"Shop" by "Products"
在"Home"之后添加"Products"时"Shop"未退出 .
这可以通过CSS解决,但除非您发布到您的商店的链接,否则无法解决 . 试试这样:
将此行添加到您的自定义CSS
如果它不起作用,可能还需要!重要
我无法评论这就是我必须回答的原因 . 请提供您网站的链接 . 我会用精确的CSS更新我的答案 .
我通过对functions.php https://www.screencast.com/t/U42lqPduY707进行更改得到了答案 .
灵感来自LoicTheAztec,这里有一个类似但略有不同的解决方案 . 假设您只想完全删除Shop链接:
复制文件: plugins/woocommerce/templates/global/breadcrumb.php
至: themes/yourtheme/woocommerce/global/breadcrumb.php
在新文件中,查找该行
然后在该行之后添加以下行:
所以最终的代码看起来像这样: