I want to insert a menu in my archive-product.php, however, I want this menu to be unique for every product page. I plan on accomplishing this by defining the menu name with the same name as the page title or page ID in woocommerce for my custom theme. and then setting my 'theme_location' => 'insert page title here'
to equal the page title dynamically.
Currently in the archive-product.php I placed this code:
<?php
$args = array(
'theme_location' => '<?php woocommerce_page_title(); ?>'
);
?>
<?php wp_nav_menu( $args ); ?>
obviously '<?php woocommerce_page_title(); ?>'
does not workdue to it being wrapped in single quotes. Is there any argument I can use to return the value of the page title? I’ve tried <?php echo get_the_title(); ?>
as well, however, same story; it is PHP wrapped inside single quotes which is seen as a text string instead code.
PS I am receptive to different methods to accomplishing this goal if this approach is simply not optimal.
If your problem are the quotes, just call it with “false” as parameter, and it will return the page title instead of echoing it. So you will have:
http://docs.woothemes.com/wc-apidocs/function-woocommerce_page_title.html
But if I were you, i’d register in functions.php all my sidebars dynamically. First, use get_posts() to fetch all the pages, then foreach page grab its title and register a sidebar with that title.