Skip to content

Instantly share code, notes, and snippets.

@jimi008
Forked from wpexplorer/gist:6574282
Created December 11, 2018 12:13
Show Gist options
  • Save jimi008/04e0f9f32e9c80da0ff78ff15e2a53bb to your computer and use it in GitHub Desktop.
Save jimi008/04e0f9f32e9c80da0ff78ff15e2a53bb to your computer and use it in GitHub Desktop.
Simple WordPress login/logout shortcode
if ( ! function_exists('wpex_loginout_shortcode') ) {
function wpex_loginout_shortcode( $atts ) {
extract( shortcode_atts( array(
'login_url' => wp_login_url(),
'log_in_text' => __( 'log in', 'wpex' ),
'log_out_text' => __( 'log out', 'wpex' ),
), $atts ) );
if ( is_user_logged_in() ) {
$url = wp_logout_url( home_url() );
return '<a href="'. $url .'" title="'. $log_out_text .'">'. $log_out_text .'</a>';
} else {
$url = $login_url;
return '<a href="'. $url .'" title="'. $log_in_text .'">'. $log_in_text .'</a>';
}
}
add_shortcode( 'loginout-link', 'wpex_loginout_shortcode' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment