• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

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 » Plugins » WP-Members » Documentation » API Functions » wpmem_do_shortcode()

wpmem_do_shortcode()

Description

This function runs a shortcode’s callback function directly without having to parse the full regex that do_shortcode() has to run. It can be used for any shortcode – not just WP-Members.

Parameters

$tag
(string) (required) The tag for the shortcode being run.

$atts
(array) (optional) Any attributes as an array.

$content
(string) (optional) Any nested content for the shortcode.

Usage

wpmem_do_shortcode( $tag, $atts, $content );

Examples

Here is an example where an attribute is included directly. The function arguments are the tag of the shortcode (in this case “wpmem_form”) and an array of the attributes. This example is the same as using [wpmem_form first_name] to display the field value in “first_name”:

echo wpmem_do_shortcode( 'wpmem_field', array( 'first_name' ) );


This is an example where there is an array key for the value. The example is the same as:
[wpmem_form login redirect_to="https://mysite.com/my-page/"]
Note that the order of arguments in the array is important. The “tag” needs to be the first attribute because the shortcode parser reads that in array key [0], so it must be first. If you set up your array values following the same order as you would for the shortcode you’re calling, it will come out right.

$atts = array(
    'login',
    'redirect_to' => 'https://mysite.com/my-page/'
);
echo wpmem_do_shortcode( 'wpmem_form', $atts );


Here is an example of a shortcode with nested content. The example would be the same result as the following shortcode:
[wpmem_logged_in]This content only displays to a logged in user[/wpmem_logged_in]
If there were additional attributes for wpmem_logged_in then those would go in the array position. In this example, however, there are no attributes, so pass either null (as in the example) or an empty array.

$content = "This content only displays to a logged in user";
echo wpmem_do_shortcode( 'wpmem_logged_in', '', $content );

Notes

  • This utility can be used for any shortcode – not just WP-Members shortcodes.  The only requirement is that WP-Members is installed and active.
  • This utility comes from J.D. Grimes. You can implement his solution directly (if needed in an instance that WP-Members is not being used).

Changelog

  • Introduced in version 3.2.5

Source

wpmem_do_shortcode() is located in /includes/api/api-utilities.php.

  • Getting Started
  • Recommended WordPress® Settings
  • Plugin Settings
    • Options
    • Fields
    • Dialogs
    • Emails
    • New Feature Settings
  • Managing Content
    • Restricting Posts
    • Restricting Pages
    • Show Excerpts
    • Custom Post Types
  • Managing Users
    • Import Users
    • Export Users
    • Edit Users
    • Search Users
  • Login
  • Registration
    • Choosing Fields
    • Create a Registration Page
    • Moderating Registration
    • Using CAPTCHA
    • Removing Registration Options
  • User Profile
  • Memberships
    • Membership Properties
    • Membership Levels
  • Menus
    • Individual Menu Items
    • Logged In Menus
    • Login/Logout Menu Link
  • Customizing Emails
    • Email Address
    • Email Content
    • Email Format
    • Email Shortcodes
    • Email Troubleshooting
  • Customizing Forms
    • Create a Custom Stylesheet
    • Using the WordPress Customizer
    • Login Form HTML
    • Registration Form HTML
    • Widget Login Form HTML
  • Translation and Localization
    • Maintain a custom translation file
    • Filter untranslated strings
    • Multi-language Considerations
  • Shortcodes
    • Pages and Forms
    • Login Status
    • User Fields
    • Memberships
    • Email
    • Other Shortcodes
  • WP-CLI Commands
  • API Functions
  • Filter Hooks
  • Action Hooks
  • FAQs
    • Email troubleshooting
    • Passwords are not being included in Emails
    • The plugin isn’t blocking my content
    • Are files protected?
    • How can I prevent registration spam?
    • How to add a shortcode
    • How to apply login redirects
    • Why can’t users log in?
    • Why does reCAPTCHA v3 fail?
    • Troubleshooting Really Simple Captcha
    • Why do I get a 403 error?
    • How do I use code snippets?
    • My changes aren’t showing up
    • How to hide the “Admin Bar”
    • How to add a forgot password link
    • Password reset doesn’t show any fields
    • Domain not included in the password reset link
    • There was an error processing the form
    • Hidden vs. Restricted
  • Demo Videos
  • How to Request Support
  • Copy Settings for Support
  • Hosting Recommendations

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