Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

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.

  • Type PHP
  • Runs Where you put the [login_link] shortcode
  • Category Shortcodes
  • Tested with WordPress 7.1
PHP
<?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.

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.