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.

I have the following code I'm trying to automatically add a menu to a theme via overriding a function. So I won't have to edit the theme file

However the menu is being outputted at the top of the page and on every page instead of only in its given location.

 /*******************************
     MENUS SUPPORT
    ********************************/
    if ( function_exists( 'wp_nav_menu' ) ){
        if (function_exists('add_theme_support')) {
            add_theme_support('nav-menus');

            function register_cbx_menus() {
                register_nav_menus(
                    array(
                        //'primary_navigation' => __( 'Main Menu'),
                        'legal_footer_navigation' => __( 'Legal Footer Menu'),
                        'echo'            => 0,
                    )
                );
            }
            add_action( 'init', 'register_cbx_menus' );
        }
    }

    //******************************************************
    //Function to override default footer credits
    //*******************************************************
    if ( !function_exists('ci_theme_footer_credits') ) {  
       function ci_theme_footer_credits() {

         // Get blog/site name
         $cbx_blogame = get_bloginfo( 'name'); 

         //$cbx_footernav = ;

         //Output new footer content
         return '<div class="cbx-footer-nav">
            &copy; '.date('Y').'&nbsp;'. $cbx_blogname .'&nbsp;'.'All rights reserved. '.wp_nav_menu( array( 'theme_location' => 'legal_footer_navigation' ) ).'</div> '
         .'<div class="cbx-poweredby">Powered by <a href="http://www.example.com" target="_blank" title="example.com">example.com</a></div>';
       }    //End function

     } //End function

How can I modify the above code to properly add the menu to a theme via the fucntion.php file without having to edit the theme file to add

wp_nav_menu( array( 'theme_location' => 'legal_footer_navigation' )); 
share|improve this question
    
I'm curious, why can't you edit the theme file or create a child theme? –  Andrew Bartel May 13 '13 at 17:55
    
because I would have edit 30+ themes –  Oudin May 14 '13 at 3:33
add comment

1 Answer

up vote 1 down vote accepted

I think your current call to wp_nav_menu() may be echoing the menu when the code is seen and not returning it in the function.

Try this call:

wp_nav_menu( array(
    'theme_location' => 'legal_footer_navigation',
    'echo'           => false,
) );

If that works, you can also probably remove the echo parameter from the register_nav_menus() call.

share|improve this answer
    
Thanks it works the only issue is using return makes the menu appear in front of everything else as oppose to exactly where I want it –  Oudin Jun 5 '13 at 23:23
    
You may be able to use the CSS z-index property to layer it behind other elements. Or you could get more help by asking a new question with a link to your test page. w3.org/TR/CSS21/visuren.html#propdef-z-index –  Charles Clarkson Jun 5 '13 at 23:29
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.