How to make wp_logout_url work with wp_nav_menu?

I’m new to wp and now trying to create a link for logging out like this:

      if ( is_user_logged_in() ) { 
        wp_nav_menu( array( 'theme_location'  => 'header-menu', 'depth' => 0,'sort_column' => 'menu_order', 'items_wrap' => '<ul id="%1$s" class="nav navbar-nav">%3$s<li><a href="<?php echo esc_url(wp_logout_url( home_url())) ?>">Logout</a></li></ul>' ) );
      }

The other parts of code are from the theme. I only want to add logout but the result shows that it’s not found.
Anybody knows how to make it work?

Read more here: How to make wp_logout_url work with wp_nav_menu?

Leave a Reply

Your email address will not be published. Required fields are marked *