WordPress.org

Support

Support » Plugins and Hacks » How to Make this section of code into a function

How to Make this section of code into a function

  • aurooba

    @aurooba

    I have this code in my header.php. Basically I widget-ized the navigation menu area, but if there are no widgets active, I have it revert to the normal nav menu.

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

    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)
  • michael.mariart

    @michaelmariart

    To make it into a function…

    function my_sidebar_function () {
        /* Add your code in here */
    }

    Calling the function…

    <?php my_sidebar_function(); ?>

Viewing 1 replies (of 1 total)
  • The topic ‘How to Make this section of code into a function’ is closed to new replies.
Skip to toolbar