Shop in breadcrumb

#773131
  • Resolved John
    Rank Math free

    Hello,
    I’ve looked hard but I can’t find how to add shop to the breadcrumb.
    I would like to add a breadcrumb like this: home/SHOP/category/product
    Thank you

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    To add the “Shop” breadcrumb to your website using Rank Math SEO and WPML, you can follow these steps:

    1. Add the provided custom code snippet to your website’s functions.php file. This code will ensure that the “Shop” breadcrumb is displayed correctly on your WooCommerce pages in secondary languages where the slug for “Shop” has been translated.
    // Fixes missing "Shop" breadcrumb in WPML translated store pages.
    if( function_exists( 'icl_object_id' ) ) {
        add_filter( 'rank_math/frontend/breadcrumb/items', 'wpmlsupp_8672_fix_wc_store_breadcrumbs', 10, 2 );
    }
    function wpmlsupp_8672_fix_wc_store_breadcrumbs( $crumbs, $class ) {
        if ( is_product() || is_product_category() || is_product_tag() ){
            $current_language = apply_filters( 'wpml_current_language', NULL );
            $default_language = apply_filters( 'wpml_default_language', NULL );
            if ($current_language !== $default_language) {
                $shop_page_id = wc_get_page_id( 'shop' );
                $shop_page    = get_post( $shop_page_id );
    
                $store_crumb = array (
                    '0' => get_the_title( $shop_page ),
                    '1' => get_permalink( $shop_page ),
                    'hide_in_schema' => ""
                );
                array_splice( $crumbs, 1, 0, array( $store_crumb ) );
            }
        }
        return $crumbs;
    }
    1. Save the changes to the functions.php file.

    By following these steps and adding the custom code snippet provided, you should be able to display the “Shop” breadcrumb on your website as “Home / Shop / Category / Product”.

    If you encounter any issues or need further assistance, feel free to ask. Thank you for reaching out!

    Sources:
    Multilingual SEO with Rank Math SEO & WPML » Rank Math
    How to Enable Breadcrumbs on Your Website With Rank Math SEO » Rank Math
    How to Customize Breadcrumbs in Rank Math » Rank Math
    How to Add the itemListElement Property Using Rank Math » Rank Math

    John
    Rank Math free

    Hello,

    Thank you for your reply,

    I don’t use WPML…

    Best

    Hello,

    Apologies for the previous reply.

    To add the shop in Rank Math breadcrumbs, you may use and customize this filter on your site:

    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
            //Adding to single products
    	if(is_singular('product')){ // change to match the post type name
                    $value[] = array(
    		'Shop', // change to the actual name shown on the frontend
                    'example.com/shop/', // change to the actual URL of your shop
                    'hide_in_schema' => false
    		);
                    //add this value as the second item in array
    		array_splice( $crumbs, 1, 0, $value ); 
    		return $crumbs; 
    	}
    	return $crumbs;
    }, 10, 2);

    You may refer to this guide on how to add filters to your website:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Hope that helps.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)

The ticket ‘Shop in breadcrumb’ is closed to new replies.