has_nav_menu example

<?php /** * Displays the site navigation. * * @package WordPress * @subpackage Twenty_Twenty_One * @since Twenty Twenty-One 1.0 */

?> <?php if ( has_nav_menu( 'primary' ) ) : ?> <nav id="site-navigation" class="primary-navigation" aria-label="<?php esc_attr_e( 'Primary menu', 'twentytwentyone' ); ?>"> <div class="menu-button-container"> <button id="primary-mobile-menu" class="button" aria-controls="primary-menu-list" aria-expanded="false"> <span class="dropdown-icon open"><?php esc_html_e( 'Menu', 'twentytwentyone' ); ?> <?php echo twenty_twenty_one_get_icon_svg( 'ui', 'menu' ); // phpcs:ignore WordPress.Security.EscapeOutput ?> </span> <span class="dropdown-icon close"><?php esc_html_e( 'Close', 'twentytwentyone' ); ?> <?php echo twenty_twenty_one_get_icon_svg( 'ui', 'close' ); // phpcs:ignore WordPress.Security.EscapeOutput ?> </span> </button><!-- #primary-mobile-menu --> </div><!-- .menu-button-container -->
wp_add_inline_script(
        'twenty-twenty-one-ie11-polyfills',
        wp_get_script_polyfill(
            $wp_scripts,
            array(
                'Element.prototype.matches && Element.prototype.closest && window.NodeList && NodeList.prototype.forEach' => 'twenty-twenty-one-ie11-polyfills-asset',
            )
        )
    );

    // Main navigation scripts.     if ( has_nav_menu( 'primary' ) ) {
        wp_enqueue_script(
            'twenty-twenty-one-primary-navigation-script',
            get_template_directory_uri() . '/assets/js/primary-navigation.js',
            array( 'twenty-twenty-one-ie11-polyfills' ),
            wp_get_theme()->get( 'Version' ),
            true
        );
    }

    // Responsive embeds script.     wp_enqueue_script(
        
/** * Displays the site header. * * @package WordPress * @subpackage Twenty_Twenty_One * @since Twenty Twenty-One 1.0 */

$wrapper_classes  = 'site-header';
$wrapper_classes .= has_custom_logo() ? ' has-logo' : '';
$wrapper_classes .= ( true === get_theme_mod( 'display_title_and_tagline', true ) ) ? ' has-title-and-tagline' : '';
$wrapper_classes .= has_nav_menu( 'primary' ) ? ' has-menu' : '';
?> <header id="masthead" class="<?php echo esc_attr( $wrapper_classes ); ?>"> <?php get_template_part( 'template-parts/header/site-branding' ); ?> <?php get_template_part( 'template-parts/header/site-nav' ); ?> </header><!-- #masthead -->

function twenty_twenty_one_body_classes( $classes ) {

    // Helps detect if JS is enabled or not.     $classes[] = 'no-js';

    // Adds `singular` to singular pages, and `hfeed` to all other pages.     $classes[] = is_singular() ? 'singular' : 'hfeed';

    // Add a body class if main navigation is active.     if ( has_nav_menu( 'primary' ) ) {
        $classes[] = 'has-main-navigation';
    }

    // Add a body class if there are no footer widgets.     if ( ! is_active_sidebar( 'sidebar-1' ) ) {
        $classes[] = 'no-widgets';
    }

    return $classes;
}
add_filter( 'body_class', 'twenty_twenty_one_body_classes' );



?> </main><!-- #main --> </div><!-- #primary --> </div><!-- #content --> <?php get_template_part( 'template-parts/footer/footer-widgets' ); ?> <footer id="colophon" class="site-footer"> <?php if ( has_nav_menu( 'footer' ) ) : ?> <nav aria-label="<?php esc_attr_e( 'Secondary menu', 'twentytwentyone' ); ?>" class="footer-navigation"> <ul class="footer-navigation-wrapper"> <?php                     wp_nav_menu(
                        array(
                            'theme_location' => 'footer',
                            'items_wrap'     => '%3$s',
                            'container'      => false,
                            'depth'          => 1,
                            'link_before'    => '<span>',
                            'link_after'     => '</span>',
                            
Home | Imprint | This part of the site doesn't use cookies.