How to Make this section of code into a function (2 posts)

  1. aurooba
    Posted 3 years ago #

    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"> <?
        				?> </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.

  2. michael.mariart
    Posted 3 years ago #

    To make it into a function...

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

    Calling the function...

    <?php my_sidebar_function(); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic