Coolest Guides on the Planet

coolest guides on the planet

Coolest Guides On The Planet

  • Home
  • macOS
  • WebDev
  • All Posts
  • Contact

Create a Login/Logout Link in WordPress

January 23, 2014 Leave a Comment

To create a login/logout link in WordPress you can use a snippet of php…

<?php if (is_user_logged_in()) : ?>
    <a href="<?php echo wp_logout_url(get_permalink()); ?>">Logout</a>
<?php else : ?>
    <a href="<?php echo wp_login_url(get_permalink()); ?>">Login</a>
<?php endif;?>

If you just want a logout link only:

<?php if (is_user_logged_in()) : ?>
    <a href="<?php echo wp_logout_url(get_permalink()); ?>">Logout</a>
<?php endif;?>

If you just want a login link only:

<?php if (! is_user_logged_in()) : ?>
    <a href="<?php echo wp_logout_url(get_permalink()); ?>">Login</a>
<?php endif;?>

You can add this anywhere in your theme template files – if you want to add as a widget – you need to enable PHP for widgets.

Cats: WordPress

Tags

3gs 10.6 apache backup baseband boot clean urls cpanel css curl custom database drupal el capitan git Google image instadmg ios iphone jailbreak keys lion mac macos mojave macos sierra menu mysql OSX panda php phpmyadmin private public redirect redsn0w remote rsa SEO shell ssh terminal unstoppables upgrade urls

Donate a Beer to the Coolest Guides

Get Beaver Builder Now!

Copyright © 2023· Neil Gee - All Rights Reserved - Hosted by Runcloud

Copyright © 2023 · gee on Genesis Framework · WordPress · Log in