back to add text

PHOTO EMBED

Wed Feb 28 2024 20:56:08 GMT+0000 (Coordinated Universal Time)

Saved by @mastaklance

// add back to text
function add_back_to_text_before_breadcrumbs($crumbs) {
    // Check if it's a product category page
    if (is_product_category()) {
        // Check if there are at least two breadcrumbs (home and one category)
        if (count($crumbs) >= 1) {
            // Get the first breadcrumb (home)
            $home_breadcrumb = reset($crumbs);

            // Get the depth of the first category
            $first_category_depth = $home_breadcrumb[2]['depth'];

            // Check if it's the first-level category
            if ($first_category_depth === 0) {
                // Add "Back to: " before the breadcrumbs
                array_unshift($crumbs, array('text' => 'Back to: ', 'url' => home_url('/')));
            }
        }
    }

    return $crumbs;
}
add_filter('woocommerce_get_breadcrumb', 'add_back_to_text_before_breadcrumbs', 10, 2);
content_copyCOPY