• 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 » Code Snippets » Re-implement [wp-members] shortcode tag

Re-implement [wp-members] shortcode tag

Chad Butler · Aug 13, 2020 ·

/**
 * Re-implement [wp-members] shortcode tag for status, page, and meta_key attributes.
 *
 * NOT intended to replace every possible use of the [wp-members] shortcode. That tag
 * is obsolete and the ideal would be to replace it accordingly. However, for instances
 * where that is not practical, this code snippet provides a solution.
 *
 * To use this code, copy/paste to your (child) theme's functions.php file or to
 * where you store custom code snippets (such as a custom plugin file for the site).
 *
 * A list of replacement shortcodes
 * @see  https://rocketgeek.com/shortcodes/list-of-replacement-shortcodes/
 *
 * This code snippet
 * @link https://rocketgeek.com/code-snippets/re-implement-wp-members-shortcode-tag/
 */
add_shortcode( 'wp-members', function( $atts, $content, $tag ) {
    
    if ( isset( $atts['status'] ) ) {
        if ( 'in' == $atts['status'] ) {
            $content = do_shortcode( '[wpmem_logged_in]' . $content . '[/wpmem_logged_in]' );
        }
        if ( 'out' == $atts['status'] ) {
            $content = do_shortcode( '[wpmem_logged_out]' . $content . '[/wpmem_logged_out]' );
        }
    }
    
    if ( isset( $atts['page'] ) ) {
        $redirect_to = ( isset( $atts['redirect_to'] ) ) ? ' redirect_to="' . $atts['redirect_to'] . '"' : '';
        switch ( $atts['page'] ) {
            case 'login':
                $content = do_shortcode( '[wpmem_form login' . $redirect_to . ']' . $content . '[/wpmem_form]' );
                break;
            case 'register':
                $content = do_shortcode( '[wpmem_form register' . $redirect_to . ']' . $content . '[/wpmem_form]' );
                break;
            case 'password':
                $content = do_shortcode( '[wpmem_form password]' );
                break;
            case 'user-profile':
                $content = do_shortcode( '[wpmem_profile]' );
                break;
        }
    }
    
    if ( isset( $atts['meta_key'] ) ) {
        $content = do_shortcode( '[wpmem_field ' . $atts['meta_key'] . ']' );
    }
    
    return $content;
});

Not sure what to do with this code?

You're not a "coder" and don't know what to do? Don't worry! Code Snippets are the basic building blocks of WordPress customization, and once you know the basics, they are simple to use.

Here are some free articles to get you started:

  • Using Code Snippets from the Site
  • Using a code snippets plugin
  • The functions.php File
  • Create a plugin file for custom functions
  • Create a child theme
  • Do not modify plugin files!

For "hands on" help, consider a plugin support subscription or the Pro Bundle.

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