WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have Genesis framework installed with a child theme. My client wants their themes "shopping cart" shortcode to be the last menu item, in their primary nav, no matter how many menu items there is.

The shortcode:

echo do_shortcode('[shopping_cart]');

Current code:

        $nav_output = sprintf
( '<div id="nav">%2$s%1$s%3$s</div>', $nav, genesis_structural_wrap( 'nav', '<div class="wrap">', 0 ), genesis_structural_wrap( 'nav', '</div><!-- end .wrap -->', 0 ) );

        echo apply_filters( 'genesis_do_nav', $nav_output, $nav, $args );



Current output:

<div id="nav">
<div class="wrap">
<ul id="menu-main-navigation-menu" class="nav">
<li id="menu-item-91" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-91">
<li id="menu-item-29" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-29">
<!-- this is where the shortcode should be placed, just before closing the list -->
share|improve this question
add_filter('wp_nav_menu_items','my_item', 10, 2);
function my_item($items, $args) {
    $items .= '<li class="myclass">whatever</li>';
    return $items;

If you have a specific theme location for menu you can target it with :

if( $args->theme_location == 'mylocation' )


you can try

$items .= '<li class="myclass">' . echo do_shortcode('[shopping_cart]') . '</li>';

but it will work only if the function is available. About the product No. - I have no idea until I see the code that produces it .

share|improve this answer
Thank you so much! Do i place that before the echo apply_filters( 'genesis_do_nav', $nav_output, $nav, $args ); line? Unsure where to place it.. – iCeR Feb 9 '12 at 3:51
put it in functions.php – user13279 Feb 9 '12 at 3:58
Thank you obmer!! – iCeR Feb 9 '12 at 4:04
Obmer, sorry one last question. I've added the following code and it now results in a "unexpected T_ECHO" error. add_filter('genesis_nav_items','cart', 10, 2); add_filter('wp_nav_menu_items','cart', 10, 2); function cart($items, $args) { $items .= '<li id="menu-item-cart" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-cart">' . echo do_shortcode('[shopping_cart]'); . '</li>'; return $items; } – iCeR Feb 9 '12 at 4:09
I do not know what other functions are hooking into the menu - you seems to have some shopping cart ? and also genesis is changing the menu ? make sure you copy my code EXACTLY as it is . if the problem is with other hooks, you can try to change the priority argument ('10') to lower or higher - depending on the other hooks ... – user13279 Feb 9 '12 at 4:13

Try this, w/dropdown

function my_contact_item($items, $args) {
  if( $args->theme_location == 'primary' )
    return $items . '<li class="myclass"><a href="http://example.com">My link title</a><ul class="sub-menu"><li><div style="width:350px;">' . do_shortcode('[My_Shortcode]') . '</div></li></ul></li>';
add_filter('wp_nav_menu_items','my_contact_item', 10, 4);

without dropdown

function my_contact_item($items, $args) {
  if( $args->theme_location == 'primary' )
    return $items . '<li class="myclass"><a href="http://example.com">My link title</a>' . do_shortcode('[My_Shortcode]') . '</li>';
add_filter('wp_nav_menu_items','my_contact_item', 10, 4);
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.