Skip to content

Instantly share code, notes, and snippets.

@gaelbillon
Created May 8, 2020 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaelbillon/8e2c1402699eb78513b425358a81f19c to your computer and use it in GitHub Desktop.
Save gaelbillon/8e2c1402699eb78513b425358a81f19c to your computer and use it in GitHub Desktop.
Wordpress with Avada Theme : Add login/logout link and my account link in main menu.
// functions.php
// Add login/logout link to main menu
// Displays as :
// Bonjour username
// (not username ? Logout)
add_action( 'avada_after_header_wrapper', 'add_loginout_link_in_header' );
function add_loginout_link_in_header( ) {
global $current_user; wp_get_current_user();
$display_name = esc_html($current_user->display_name);
$items = '';
// if ($args->theme_location == 'main_navigation') {
if (is_user_logged_in()) {
$items .= '<p>'; //class="login_logout_in_main_menu"
$items .= '<p>Bonjour <a href="/mon-compte">' . $display_name . '</a></p>';
$items .= ' (pas ' . $display_name . ' ? ' . '<a href="/mon-compte/customer-logout">'. __("Log Out") .'</a>)';
// $items .= '</li>';
} else {
$items .= '<li class="right"><a href="/mon-compte">'. __("Log In") .'</a></li>';
}
// }
echo $items;
}
// Style.css
/* Prevent line break for login/logout link in main menu */
.fusion-main-menu ul li.login_logout_in_main_menu a {
display: inline;
font-size: 14px;
}
.fusion-main-menu ul li.login_logout_in_main_menu {
font-size: 14px;
cursor: default;
}
.fusion-main-menu ul li.login_logout_in_main_menu p {
margin-top: 0;
margin-bottom: 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment