Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save prosantamazumder/4baff8d4930b06c67847aa55c1cdf36c to your computer and use it in GitHub Desktop.
Save prosantamazumder/4baff8d4930b06c67847aa55c1cdf36c to your computer and use it in GitHub Desktop.
If User Logged in then show something and show another
//Add This Code Function.php
function add_loginout_link( $items, $args ) {
if (is_user_logged_in() && $args->theme_location == 'primary_menu') {
$items .= '<li><a href="'. wp_logout_url() .'">Log Out</a></li>';
}
elseif (!is_user_logged_in() && $args->theme_location == 'primary_menu') {
$items .= '<li><a href="'. site_url('wp-login.php') .'">Log In</a></li>';
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 );
==================
if ( is_user_logged_in() ) {
// your code for logged in user
} else {
// your code for logged out user
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment