• Resolved harlequinsyndrom

    (@harlequinsyndrom)


    I’m trying to add a conditional menu for a specific site. It’s working in the header, but not in the footer. I’m pretty sure I’ve made some php mistake, because I’m working on s.o. elses template.

    Here’s my relevant code from function.php:

    function corporate_name_setup() {
    		
    		// This theme uses wp_nav_menu() in one location.
    		register_nav_menus( array(
    			'menu-1' => esc_html__( 'Primary', 'corporate_name' ),
    		) );
    }
    
    function corporate_name_menus_init(){
        register_nav_menus( array(
            'main-menu' => 'Main Menu',
            'primary-sub-menu' => 'Primary Sub Menu',
            'primary-footer-menu' => 'Primary Footer Menu',
    		'footer-menu-1' => 'Footer Menu 1',
    		'footer-menu-2' => 'Footer Menu 2'
        ) );
    }
    

    It’s working in the header.php, so here’s the code:

    <header id="masthead" class="site-header">
            <div class="header-wrapper">
                <div class="site-branding">
                    <a href="<?php echo esc_url(home_url('/')); ?>" rel="home"><img
                                src="<?php echo get_template_directory_uri() . '/assets/images/unique_projects_logo.svg' ?>"
                                alt="<?php echo get_bloginfo(); ?>"></a>
                </div><!-- .site-branding -->
    
                <div class="nav-toggle">
                    <div id="toggle-main-nav">
                        <div id="burger-icon">
                            <span></span>
                            <span></span>
                            <span></span>
                            <span></span>
                        </div>
                        <div class="nav-toggle-title">Menu</div>
                    </div>
    
                    <div class="navigation-main-menu">
                        <?php
                        wp_nav_menu(array(
                            'theme_location' => 'main-menu',
                        ));
                        ?>
                    </div>
                </div>
    
                <nav id="site-navigation" class="main-navigation">
    
                    <div class="navigation-primary-menu">
                        <?php
                        wp_nav_menu(array(
                            'theme_location' => 'menu-1',
                            'menu_id' => 'primary-menu',
                        ));
                        ?>
                    </div>
                    <div class="navigation-primary-sub-menu">
                        <?php
                        wp_nav_menu(array(
                            'theme_location' => 'primary-sub-menu',
                        ));
                        ?>
                    </div>
    
                    <div class="clear"></div>
    
                    <div class="navigation-primary-footer-menu">
                        <div class="sub-navigation nav-footer-box">
                            <?php
                            wp_nav_menu(array(
                                'theme_location' => 'primary-footer-menu',
                            ));
                            ?>
                        </div>
                        <div class="copyright nav-footer-box">© <?php echo date('Y') ?> unique projects GmbH & Co. KG</div>
                    </div>
    
                </nav><!-- #site-navigation -->

    And the footer.php, where it’s not working at all:

    <div class="footer-widget menu-1"> 
                <?php if (is_active_sidebar('footer-widget-2')) {
                    if (function_exists('dynamic_sidebar') && dynamic_sidebar('Footer Widget 2')) : ?>
                    <?php endif;
                } ?>
            </div>
    
            <div class="footer-widget menu-2">
                <?php if (is_active_sidebar('footer-widget-3')) {
                    if (function_exists('dynamic_sidebar') && dynamic_sidebar('Footer Widget 3')) : ?>
                    <?php endif;
                } ?>
        </div> 
    

    I’m aware that the code is different than the one used in the header, but I tried it like in the header and just got a long list with every on this page created link.

    I’m greatful for every help I can get. What am I doing wrong?

    Edit: that’s not my code I’m working on, just trying to get it to work.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter harlequinsyndrom

    (@harlequinsyndrom)

    I solved it, the footer.php was the problem.

    Here’s what I did to make it work:

    <div class="footer-widget menu-1">
                        <?php
                        wp_nav_menu(array(
                            'theme_location' => 'footer-menu-1',
                        
                        ));
                        ?>
                    </div>
    		<div class="footer-widget menu-2">
                        <?php
                        wp_nav_menu(array(
                            'theme_location' => 'footer-menu-2',
                        
                        ));
                        ?>
                    </div>
    Plugin Author themifyme

    (@themifyme)

    Glad to hear you’ve sorted it. FYI: It needs to have wp_nav_menu function for Conditional Menus to work.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Conditional Menu not working in footer.php’ is closed to new replies.