Created
September 19, 2019 18:59
-
-
Save pagelab/0cb9cf8fa24be04b7eb9c365767ccadf to your computer and use it in GitHub Desktop.
Adicionando um link de login/logout no menu principal do tema.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // Don't add this line if inserting in a functions.php file. | |
add_filter( 'wp_nav_menu_items', function( $items, $args ) { | |
// Only used on main menu | |
if ( 'main_menu' != $args->theme_location ) { | |
return $items; | |
} | |
// Add custom item | |
$items .= '<li class="mmy-custom-login-logout-link menu-button menu-item">'; | |
// Log-out link | |
if ( is_user_logged_in() ) { | |
$text = 'Logout'; | |
$logout_redirect = home_url( '/' ); // Change logout redirect URl here | |
$items .= '<a href="'. wp_logout_url( $logout_redirect ) .'" title="'. esc_attr( $text ) .'" class="wpex-logout"><span class="link-inner">'. strip_tags( $text ) .'</span></a>'; | |
} | |
// Log-in link | |
else { | |
$text = 'Login'; | |
$login_url = wp_login_url(); // Change if you want a custom login url | |
$items .= '<a href="'. esc_url( $login_url ) .'" title="'. esc_attr( $text ) .'"><span class="link-inner">'. strip_tags( $text ) .'</span></a>'; | |
} | |
$items .= '</li>'; | |
// Return nav $items | |
return $items; | |
}, 20, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment