• Skip to primary navigation
  • Skip to main content

RocketGeek

Home of WP-Members, The Original WordPress Membership Plugin

  • WordPress Plugins
    • WP-Members
      • FAQs
      • Quick Start
      • Documentation
      • Extensions
    • Advanced Options
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Download Protect
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Invite Codes
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • MailChimp Integration
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • PayPal Subscriptions
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Salesforce Web-to-Lead
    • Security
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Text Editor
      • Purchase the Plugin
      • Get the Pro Bundle
    • User List
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • User Tracking
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Memberships for WooCommerce
    • WordPass
  • Blog
    • Basics
    • Tips and Tricks
    • Filters
    • Actions
    • Code Snippets
    • Shortcodes
    • Design
    • Release Announcements
  • Store
    • Cart
    • Checkout
  • Contact
  • Log In
  • Show Search
Hide Search
Home » Tips and Tricks » Redirecting WordPress urls for login, logout, and registration

Redirecting WordPress urls for login, logout, and registration

Chad Butler · Oct 9, 2012 ·

This article is provided free. Find out how you can get full access to premium content, including how-to articles and support forums, as well as priority email support and member exclusive plugin extensions..

 

Depending on a number of factors, there may be places in your WordPress site where login and logout URLs are directing to the WordPress “backend” wp-login.php.  These can be in the comments.php template or other places in your theme.  Also, various plugins such as forums will utilize these urls.

This article will explain a simple way of redirecting these URLs to the login and registration pages set in WP-Members.

NOTE: The WP-Members Advanced Options extension has simple checkbox options to replace the native WP URLs for these actions with the WP-Members URLs.

This process makes use of some little known and little used WordPress filters, login_url, logout_url, and register_url. These can be used to direct any call to wp_login_url(), wp_logout_url(), or wp_registration_url() to the locations you want to direct to.

logout_url

First, a logout filter. The logout_url hook will allow you to filter the url the user is directed to when they logout. With WP-Members, if you direct to any page in the site with the querystring ?a=logout the logout function will be executed. (If you want the user to be redirected to a specific URL AFTER they logout, that is something for the wpmem_logout_redirect filter.)

A couple notes about the URL you redirect to: It should be obvious that you’ll need to make this appropriate to your domain. Also, I set this example based on WordPress being located in the root of your site. If you are running WP in a subdirectory you might have to adjust accordingly.

add_filter( 'logout_url', function( $url ) {
     return 'https://yourdomain.com/?a=logout';
});

login_url

The login redirect is similar, but using a different hook: login_url. Set the URL to whatever page you want users to login in on. That could be a page that you’ve set up with the WP-Members login page shortcode, or really any other page that has login on it. Set the URL according to your specific need (i.e. the url of your login page). This code will also provide a redirect link back to the page the user was on when they clicked the login link.

add_filter( 'login_url', function( $url ) {
     $login_page = 'https://yourdomain.com/your-login-page/'
     $redirect_to = get_permalink();
     return add_query_arg( 'redirect_to', $redirect_to, $login_page );
});

If you have set a login page in the plugin’s settings, this snippet is similar to the above but will pick up your login page setting, using the plugin API function wpmem_login_url() to get the login url location and wpmem_current_url() to get the url to redirect back to:

add_filter( 'login_url', function( $url ) {
     return add_query_arg( 'redirect_to', wpmem_current_url(), wpmem_login_url() );
});

register_url

This filter can be used to filter the location of the registration form generated by wp_registration_url:

add_filter( 'register_url', function( $url ) {
     return 'https://yourdomain.com/your-registration-page';
});

If you have set a registration page in the plugin’s settings and want to redirect to that, here is a slightly different snippet that uses the wpmem_register_url() to get the WP-Members register page setting:

add_filter( 'register_url', function( $url ) {
     return wpmem_register_url();
});

Usage

As with any filters, these can be used in your theme’s functions.php file.

Alternate Option

The WP-Members Advanced Options extension has simple checkbox options to replace the native WP URLs for these actions with the WP-Members URLs.

Tips and Tricks filters, tips, wp-filters

Ready to get started?

Join Today!

© 2025 · butlerblog.com · RocketGeek is built using WordPress, WP-Members, and the Genesis Framework

  • butlerblog.com
  • WP-Members Support Subscription
  • Terms of Service
  • Privacy Policy
  • Refund Policy