beans_breadcrumb() should check for false return from get_post_type_archive_link()
@see https://community.getbeans.io/discussion/wrong-woocommerce-breadcrumbs/ for initial report.
WooCommerce Products have no archive link. So we end up with an entry in $breadcrumbs like
[0] => 'Products'
where [0] should be a url.
Presumably this would be the case for any CPT object for which has_archive is not set or false. Checking for it is easy enough, but what to do in these events?
We probably ought to implement a check for WooCommerce, since this will be a common case. Beyond that some things that come to mind:
- We could attempt to find taxonomies/terms belonging to the CPT.
- We could insert a placeholder key and then output the PostType label without linking.
- We could just bail out of that iteration and leave that bit of the breadcrumb out, since it's essentially inaccessible for a visitor anyway.
Hi there, I found a solution for this case Add code to function.php (child theme)
add_action( 'after_setup_theme', 'woocommerce_support' ); function woocommerce_support() { add_theme_support( 'woocommerce' ); add_theme_support( 'wc-product-gallery-zoom' ); add_theme_support( 'wc-product-gallery-lightbox' ); add_theme_support( 'wc-product-gallery-slider' ); }
Woo will add their breadcrumb by default on all shop pages.
To remove theme breadcrumbs on shop pages(avoid duplicate), just add
add_action ('wp' , 'woo_dup_disable_breadcrumb'); function woo_dup_disable_breadcrumb() { if ( is_woocommerce() ) { // Remove the breadcrumb. add_filter( 'beans_pre_load_fragment_breadcrumb', '__return_true' ); } }
It works, however, if you disable the woocommerce plugin, you need to remove the code above in function.php file. I'm looking for the function that working if woo is disabled but no luck. Tried this solution https://docs.woocommerce.com/document/query-whether-woocommerce-is-activated/ but theme breadcrumb still appear with Woocommerce breadcrumb on shop pages.
@iCaspar Where do we stand on this issue?
I'm thinking we can roll this issue into the Beans WooCommerce plugin, i.e. yet to be developed. Let's target for that plugin.