A Guide to Using Shortcodes

This Article Applies to

In this article we’re going to take you from Shortcode Beginner to ShortCode Ninja. If you find yourself confused, or lost when reviewing this, reach out to us at support for assistance.

What Are Shortcodes?
Shortcode Attributes

Pro Tips
Conditional Shortcodes
How to Nest Shortcodes

Ninja Tips
Formatting Your Output
Local Variables
Capturing Your Output for Later
Using Shortcodes in your PHP code

The Other Stuff
Changes in WordPress Shortcodes
Troubleshooting Shortcodes

What Are Shortcodes?

Shortcodes are powerful little commands that you can use in your pages to make your site do different things. WordPress comes with a set of built-in shortcodes, and most themes and plugins add their own shortcodes as well.

Memberium provides you a powerful toolbox of shortcodes for creating, automating and making your membership site interactive.

WordPress shortcodes look similar to HTML tags, consisting of a phrase surrounded by a set of square brackets []. A shortcode can take parameters, which we often call “attributes”. A shortcode can stand by itself, or it can consist of an opening and closing shortcode and contain content. We’ll show you simple examples of all these below:

All Memberium shortcodes are in all lowercase, and start with “memb_”. The following are some examples of how shortcodes are used, you can try these examples on your own site to see how they work:

A simple shortcode by itself:


A simple shortcode, with attributes:

[memb_echo value='Hello, World']

A shortcode containing content with opening and closing codes:

Only show this to admins

A shortcode with attributes and content:

[memb_has_any_tag tagid=123]
Only show this to people with tag #123

Shortcode Attributes

Shortcode attributes allow one shortcode to do many different things. For example, Memberium has one shortcode for displaying the fields of the currently logged in Infusionsoft contact. The attributes let you tell the [memb_contact] shortcode which of the fields to display, and how to display it. The names of shortcode attributes are always all in lowercase.


[memb_contact fields=FirstName]

IF the value of your attribute has spaces in it, then you’ll need to enclose it in quotes so that WordPress knows where your value starts and finishes. You can use single quotes, or double quotes.

[memb_echo value="Hello, World"]
[memb_echo value='Hello, World']

If you have several attributes, it doesn’t matter what order they are used in. These examples work exactly the same:

[memb_echo value='Hello, World' txtfmt=strtoupper]
[memb_echo txtfmt=strtoupper value='Hello, World']

Conditional Shortcodes

Conditional shortcodes do a test and then allow you to choose what content to display depending on what the results of the test were. Tests always result in a yes/no, true/false, success/failure result. Conditional shortcodes usually contain a word like “is” or “has”, indicating a condition. All tests are simple true-false / sucess-fail / yes-no tests.

Conditional shortcodes can be used three different ways:

You can use the shortcode by itself. It will displays “Yes” if the shortcode test passes, or “No” if it fails.



With many shortcodes you can use the attribute “output” to display something instead of “Yes”.


[memb_has_any_tag tagid=123 output='It Worked!']

Often you want to control a large amount of content. You can control whether a block of content is dislpayed by wrapping your shortcode around it. The content in the shortcode is displayed if the test passes, and not displayed if the test fails. The content blocks can be as large as you want. To create a closing shortcode use “/” at the beginning of the closing shortcode.


You are Logged In

Sometimes you will want to display content if the test fails, you can do this by wrapping your shortcode around two blocks of content, one for a successful test, and one for a failed test, and separating them with the [else_memb_*] shortcode.


You are Logged in
You are not logged in

Example with no “success” content:

You are not logged in

Nestable Shortcodes

Sometimes you need to do multiple tests and have them all done to decide whether to decide to display the content or not. Placing one shortcode inside another is called nesting. Most conditional shortcodes are nestable.

If the second test follows after the first test completes, that is not nesting, and you don’t need to use the nesting ability. You can have as many tests on the page as you want. You only need to nest them if the next test starts before the previous test finishes.

There is a predetermined number of times that any given shortcode can be nested.

To nest a shortcode simply add a number to the end of the shortcode name. Similarly for [else_ and closing shortcode markup, you would add the number on as well. By default you can have up to 10 levels deep, shortcode and shortcode1…shortcode9. If you DO need to nest shortcodes deeper than 10 levels, please contact support.

Some examples


Text Formatting

Most Memberium shortcodes also support passing a txtfmt parameter that lets you specify a comma delimited list of text processing functions that will be applied on the output. If you use txtfmt and capture together, the text formatting will be applied first and then the result will be captured. You can stack functions together and they will be applied in order from first/left to last/right. You can stack as many of these text formatting codes together as you wish.

Quote string with slashesbin2hex
Convert binary data into hexadecimal representation. The conversion is done byte-wise with the high-nibble first.convert_uudecode
Decodes the output which must be a uuencoded string.convert_uuencode
Encodes the output using the uuencode algorithm. Uuencode translates all strings (including binary’s ones) into printable characters, making them safe for network transmissions. Uuencoded data is about 35% larger than the original.

Outputs the crc32 polynomial of the content.

Performs a one-way string hashing on the output. Caution: No salt is used.

Convert all HTML entities to their applicable characters.

Convert all applicable characters in the output to HTML entities.

Convert special characters to HTML entities.

Convert special HTML entities in the output back to characters.

Make the output’s first character lowercase.

Strip whitespace from the beginning of the output.

Returns the md5 hash of the output.

Inserts HTML line breaks before all newlines in a string

Converts all accent characters to ASCII characters. If there are no accent characters, then the output is unaltered.

Strip whitespace from the end of the output.

Outputs the SHA1 hash of a string.

Outputs the ROT13 encoding of a string. The ROT13 encoding shifts every letter by 13 places in the alphabet while leaving non-alpha characters untouched. Encoding and decoding are done by the same function, passing an encoded string as argument will return the original version.

Un-quotes a quoted string.

Returns the length of the output. The length is measured in bytes.

Reverses the output.

Make the output lowercase.

Make the output uppercase.

Make a string’s first character uppercase.

Strip whitespace (or other characters) from the beginning and end of a string.

Uppercase the first character of each word in a string. The definition of a word is any string of characters that is immediately after a whitespace (These are: space, form-feed, newline, carriage return, horizontal tab, and vertical tab).

This returns given text with transformations of quotes to smart quotes, apostrophes, dashes, ellipses, the trademark symbol, and the multiplication symbol. Text enclosed in the tags pre code, kdb, style, script and tt will be skipped.

The following example outputs the first name, converted to all lowercase

[memb_contact fields=FirstName txtfmt=strtolower]

The following example outputs the first name, converted to all lowercase, and then the first letter uppercase’d.

[memb_contact fields=FirstName txtfmt=strtolower,ucwords]

Local Variables

Sometimes you need to change the values you’re comparing or using in your shortcodes on the fly, so that they’re different depending on the conditions.

Memberium is able to store data about the current visitor in the local WordPress database, instead of Infusionsoft. This provides essentially unlimited fields (limited only by memory and disk space) for storing additional information.

You can capture data into local variables, you can display those variables to the screen, and you can use those variables in the attributes of Memberium shortcodes.

Local variables can be embedded into attributes by wrapping the variable in double curly braces “{{}}”. We support several kind of variables and some of those variables have different formats, and we may extend those formats as we make the system more capable. Here’s some examples:

To display fields from your visitor’s contact data, use the “contact.” followed by the name of the field. Contact fields are not case sensitive:


Using information from a contact’s affiliate record:


You can use information about the server’s current date/time, and format it as you need.

Using the date in Year Month Day format:


Using the current server time in hour format:


Custom Fields:


The visitor’s IP Address:


Random numbers:


GET/POST/Session Values:








Capturing Your Output

Most Memberium shortcodes let you control what is done with the output of your shortcodes. Under normal use, the shortcode is simply displayed to the browser. However, you can also save the output for later by capturing it into a custom local variable. you pass a shortcode attribute of “capture” with a comma separated list of destinations to send the output of the shortcode. It does not matter what order the destinations are listed in

Current parameters you can use in the capture parameter are:

display – Displays the output as usual. If you have capture specified and omit this, then the normal display of the shortcode won’t happen.

field:fieldname – Captures the output of the shortcode into the custom local variable field stored in WordPress.

Example, capturing first and lastname without displaying it:

[memb_contact fields="FirstName,LastName" capture="field:FullName"]

Example, capturing the output AND displaying it

[memb_contact fields="FirstName,LastName" capture="display,field:FullName"]

Using Shortcodes in your PHP Code

Shortcodes are automatically processed when used in Menus, Widgets and Page/Post content. If you wish to use the shortcodes in your PHP code, you can easily do this using WordPress’s do_shortcode function.


<!--?php echo do_shortcode('[memb_contact fields=FirstName]'); ?-->

If you’re doing a conditional shortcode, the entire shortcode needs to be processed at once.


<!--?php echo do_shortcode('[memb_has_any_tag tagid=123]Success[else_memb_has_any_tag]Failure[/memb_has_any_tag]'); ?-->

Troubleshooting Shortcodes

In some situations you may find that shortcodes stop working, or show up oddly on the page. This is easily fixable.

If you are running OptimzePress 2.0 and only parts but shortcodes are visible up to the quotes and unprocessed on your site, then you may be hitting an issue with how OptimizePress stores your content. You can easily work around this by replacing the double quotes in your shortcode with single quotes, or by using no quotes at all as long as there are no spaces in your parameters.

  • Was this Helpful?
  • YesNo
9 ways to add more value to your membership site

Table of Contents

This Article Applies to

Keep Reading

Private Comments

Memberium’s Private Comments feature gives you the ability to easily make comments for any page or post private, so that only the administrators, the author of the page/post, and the author of the comment can see the comment on the page.

Read More »

Enable User URL Slug Update

Enable User URL Slug Update allows you to control whether or not the WordPress user slug will be changed when the display name is updated. By default, this is not enabled. Some plugins like BuddyBoss or BuddyPress use the user slug to create individual profile pages.

Read More »

Default Logout Page

Sets the default URL for visitors to be sent to on logout. If no default URL is set, and no membership level logout page is set, the site’s homepage will be used.

Read More »

Want to get some fresh ideas on how you can improve your membership site or course?

Download our free ebook!

Book a Call

Welcome to Memberium!

We are very excited for you to be part of our family. 

We would love to answer any questions that you have!

Please choose the best time for you to get in a call with us. 

For Technical Support, you can contact us at https://keap.memberium.com/support/ or Email us at support@memberium.com.