Support » Theme: Twenty Twelve » Add Function to check if Navigation Widgets active

  • Resolved aurooba



    As a disclaimer, I don’t know any PHP, and this is my first venture into it. Basically, I widget-ized the navigation area in Twenty Twelve, but what I want to do is check if there are any widgets active in that area, and if not, use the default navigation menu coding. I know I’m doing it terribly wrong and probably breaking PHP practices.. here’s what I’ve doesn’t work (breaks my installation), but I’m hoping someone can help me. :

    function checknav() {
    	if ( ! is_active_sidebar( 'nav-widgets' ) ) {
    				echo '<?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu' ) ); ?>';
    add_action( 'widgets_init', 'checknav' );

    Any help is appreciated. Thanks!

Viewing 1 replies (of 1 total)
  • aurooba


    Nevermind! Fixed it!

    Instead of making a function, where I had the widget-ze code in header.php, I made it an if statement, so if nav-widgets wasn’t active, it would insert code for regular menu, and if it is active, then show the widgets! 🙂

    <?php if ( ! is_active_sidebar( 'nav-widgets' ) ) {
    				wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu' ) );
    } else {
        				?> <div id="nav-widgets"> <?
        				?> </div> <?
    } ?>

    But I’d love if someone could show me how to convert this into a function and then call it in the appropriate place in header.php.

Viewing 1 replies (of 1 total)
  • The topic ‘Add Function to check if Navigation Widgets active’ is closed to new replies.