Site logo

Archived topic

Login link in footer

3 replies · Started by Hashim on April 15, 2021

Viewing posts 1–4 of 4

Hi there,

Does anyone know how I can add a login link in the footer that changes in a log out link when a user is logged in?

My website is just a regular blog and the users are editors. Nothing special. Also I'm using the standard login pages and functionality of WordPress.

I'm not a coder and some basic html to create a link is as for as my coding skills go. But I'm hoping that there's some standard or easy way to add a login link to the footer (or navigation).

Thank you in advance for your help!

Sincerely,

Hashim

Hi there,

WP doesn't actually provide you with a simple way to do this.
There are plugins that you can use. But if you don't want to use a plugin then add this PHP Snippet to your site:

add_shortcode( 'login-link','add_login_logout_link' );
function add_login_logout_link() {
  if ( is_user_logged_in() ) {
	echo '<a href="'.wp_logout_url().'" title="Logout">Logout</a>';
   } else {
	echo '<a href="'.wp_login_url().'" title="Login">Login</a>';
  }
}

How to add PHP: https://docs.generatepress.com/article/adding-php/

Then you can add this shortcode to a widget: [login-link]

Hi David,

Thank you so much for your answer!

I'll give it a try as soon as I can and I'll let you know how that worked out.

But...

If I would like to do this with a plugin, which plugin would you recommend? I know you guys live for performance. That's also why I chose Kinsta and try to follow al of your and their recommendations. So if you know of a plugin that you'd recommend for this, I'd really like to know.

Thank you in advance!

This archived topic is closed to new replies.