Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

(Moderator's note: The original title was "How can I create a widget area in the navigation bar (Genesis specific)?"(

I'm trying to create a widget area in my navigation bar. I'm attempting to adapt this from Bill Erickson's excellent tutorial here on adding static content to the navigation bar.

This is the code I've added to my functions.php file to register and place the widget area:

    genesis_register_sidebar(array(
    'name'=>'Nav Right',
    'description' => 'This is the right section of the navbar.',
    'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget'  => '</div>',
    'before_title'=>'<h4 class="widgettitle">','after_title'=>'</h4>'
));

//Adding the widget area to the navbar
add_filter('genesis_nav_items','navbar_widget',10,1);
add_filter('wp_nav_menu_items','navbar_widget',10,1);
function navbar_widget() {
    ?>
    <div class="nav_right">
    <?php if (!dynamic_sidebar('Nav Right')) : ?>
            <div class="widget">
            <h4><?php _e("Nav Right", 'genesis'); ?></h4>
            <p><?php _e("This is a widgeted area which is called Nav Right.", 'genesis'); ?></p>
        </div>
    <?php endif; ?>
    </div><!-- end .nav-right -->
    <?php
}

However, what I end up with is this:

alt text

With the widget area outside of the navigation bar (and the links removed from the navigation bar - there should be a Home and About link there).

This is the html (when I view source of the page):

<body class="home blog logged-in content-sidebar"> 
 <div id="wrap"> 
<div id="header"><div class="wrap"><div id="title-area"><h1 id="title"><a href="http://travisnorthcutt.com/gateway/" title="Research Valley International Gateway">Research Valley International Gateway</a></h1><p id="description">Just another WordPress site</p></div><!-- end #title-area --><div class="widget-area"></div><!-- end .widget_area --></div><!-- end .wrap --></div><!--end #header--> 
   <div class="nav_right">
                <div class="widget">
            <h4>Nav Right</h4>
            <p>This is a widgeted area which is called Nav Right.</p>
        </div>
        </div><!-- end .nav-right -->
  <div id="nav"><div class="wrap"></div></div>

Any suggestions on how to get the new widget area that is created to be within <div id="nav"></div>?

share|improve this question
    
I feel this question is better asked on the StudioPress forums. This site should not devolve into a channel for free support for premium themes –  Ash G Oct 6 '10 at 23:51
    
This question has also been asked on the SP forums ;-). I think it's a good question to ask here - it's technical in nature, and (I think) will have an objective solution. Trust me, I'm not trying to cause this site to 'devolve' into free support for premium themes. I have paid for a license for StudioPress themes and by no means am I trying to get "free" support somehow. –  tnorthcutt Oct 7 '10 at 1:48
    
Do these type of questions belong on this site? Join the discussion on Meta! –  Jan Fabry Oct 7 '10 at 7:42
    
@Ash G: Is it really a problem to have answers to 3rd party solutions here? I for one would love to have them here because otherwise we'll be at the mercy of much poorer support mechanisms offered by those 3rd parties. Said another, what does it hurt? –  MikeSchinkel Oct 7 '10 at 10:24
    
As per our discussion on meta, I retract my complaint and throw myself behind the question. As soon as my vote is unlocked (have to wait, it's only been 12 hours) I will reverse it. Love the fact that we can ask, answer, debate and convince! –  Ash G Oct 7 '10 at 12:26
show 1 more comment

1 Answer

up vote 1 down vote accepted

You are adding filter, not an action. I don't know how Genesis hook works, but native wp_nav_menu_items passes (and expects back) markup of custom menu items.

Instead of echoing your additional stuff you should append it to input and return.

This is clearly how it's done in tutorial you linked to:

add_filter('wp_nav_menu_items','follow_icons',10,1);
function follow_icons($output) {
    $follow = 'some stuff';
    return $output.$follow;
}

Upd. Forgot to add about sidebar part. Since sidebars are echoed by definition you will likely have to buffer its output to use in such fashion. Maybe instead of making widget ares literally inside menu it is better to look for hook that allows to do this nearby?

share|improve this answer
add comment

Your Answer

 
discard

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.