WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. aurooba
    Member
    Posted 1 year 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"> <?
        				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.

  2. michael.mariart
    Member
    Posted 1 year 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