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.
(string) (required) The tag for the shortcode being run.
(array) (optional) Any attributes as an array.
(string) (optional) Any nested content for the shortcode.
wpmem_do_shortcode( $tag, $atts, $content );
Example where an attribute is included directly:
// This will display the value of "first_name" for the current user. echo wpmem_do_shortcode( 'wpmem_field', array( 'first_name' ) );
Example of an attribute that needs an array key:
$atts = array( 'login', 'redirect_to' => 'https://mysite.com/my-page/' ); echo wpmem_do_shortcode( 'wpmem_form', $atts );
Example of a shortcode with content:
$content = "This content only displays to a logged in user"; echo wpmem_do_shortcode( 'wpmem_logged_in', '', $content );
- 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).
- Introduced in version 3.2.5
wpmem_do_shortcode() is located in /inc/api-utilities.php.