How to get title of current page with WooCommerce

Good morning all,
I have a problem with WooComerce breadcrumbs. I want to add breadcrumbs bar with current page/product title on left side. But i have no idea how can I get this title. I was able to add some custom text and move it to right with this code:

'wrap_before' => '<nav class="woocommerce-breadcrumb"><h1 id="name">Some text</h1>',
 'wrap_after'  => '</nav>',

Can you please suggest me some solution to get the title?

Read More

EDIT: Okey i manage to get some temporary results but its return only WooComerce pages name (shop,category names) it dont show product names. Any suggestions ?

Here is code:

 <script type='text/javascript'>
   /* <![CDATA[ */                      
      jQuery(document).ready(function() {
         jQuery("#name").append("<?php echo woocommerce_page_title();?>");
                                    });
                                    /* ]]> */
                                </script>  

Related posts

1 comment

  1. I would use the woocommerce_get_breadcrumb filter to modify the contents of the array that is sent to the template. You can take the page name from the end and put it onto the beginning, or add any other breadcrumbs you want. Each element is an array with the first element being the text and the second element is the link.

    // filter the array that is sent to the breadcrumbs template
    add_filter( 'woocommerce_get_breadcrumb', function( $crumbs ){
        // remove the last element (this is the page name by default)
        $page_crumb = array_pop( $crumbs );
    
        // add it back to the beginning of the array. 
        // you can change this to whatever you want, it's an array( 'Text', '/link' )
        array_unshift( $crumbs, $page_crumb );
    
        // return the modified array
        return $crumbs;
    } );
    

Comments are closed.