Log in / log out link shortcode
Type [login_link] to show “Log in” for visitors and “Log out” for logged-in users, returning them to the same page afterwards.
<?php
// [login_link]
$here = is_singular() ? get_permalink() : home_url( '/' );
if ( is_user_logged_in() ) {
return '<a href="' . esc_url( wp_logout_url( $here ) ) . '">' . esc_html__( 'Log Out' ) . '</a>';
}
return '<a href="' . esc_url( wp_login_url( $here ) ) . '">' . esc_html__( 'Log In' ) . '</a>';
How to use it
Type [login_link] in a post, a page or a Shortcode block.
In these packs
- Shortcodes: Handy shortcodes for dates, breadcrumbs, buttons, share links, members-only content and more.