Groups’ shortcodes are used to protect content sections, show group information, let a user join or leave a group, show user or site groups etc.
Don’t worry if you are not familiar with the usage of shortcodes, easy to follow examples are provided in each section to show you how to use them. Using shortcodes is not coding – to give you an idea of how super easy to use this is, the example below shows how you can restrict content to be displayed for registered users only – you can use snippets like this anywhere on a post, a page and other types of entries on your site:
[groups_member group="Registered"]
Only registered members can see this.
[/groups_member]
As in this example, many shortcodes require you to indicate an attribute. This is so that Groups knows how to act, based on hints about groups, capabilities or other information it requires along with the shortcode. Note that you pass information to these attributes enclosed within plain double quotes ".
The following sections provide details on the usage of the shortcodes included in Groups:
We provide usage examples where appropriate in each of these sections.
The documentation on Content Sections provides additional examples and information on the use of some shortcodes.
Shortcodes or Blocks?
If you prefer to use blocks, you can use the membership Blocks that Groups provides. However, if you would like to make yourself familiar with shortcodes, you can follow the examples on these pages. You can also read about shortcodes in general on the WordPress Shortcode codex page.
Shortcode Validation – When Shortcodes aren’t Processing
When you put a Groups shortcode inside certain third-party plugins (like custom page builders, table creators, or advanced layout containers), the shortcode might simply show up empty or as plain text instead of working.
This happens because Groups includes a built-in security feature: it scans the standard WordPress post content to verify that a shortcode was actually written there before it allows it to run. However, many third-party plugins store their content in specific fields, custom database tables or layout blocks. Because Groups cannot find the shortcode where it would expect it and validate it, it blocks it from processing for safety reasons. As the shortcodes that come with Groups relate to access restrictions and restricted content, this is a critical security feature.
If you are using one or more of the shortcodes and the expected content is not shown, please review the information on the Validation page.
Visual Appearance
Please note that how the shortcodes are rendered depends on the theme that is being used. Groups is pretty neutral and lets you customize the output using simple CSS rules.
Depending on your theme, don’t expect the output you obtain to look exactly as in our examples.
The HTML that our shortcodes produce can be themed easily, as it usually adds appropriate CSS classes to key elements rendered.
Using shortcodes in Templates
Besides placing shortcodes on posts, pages, etc., you can use the shortcodes in your PHP template files. We can use WordPress’ do_shortcode() function for this purpose.
Here is a very simple example that will render the text Hello member! for registered users:
<?php echo do_shortcode(
'[groups_member group="Registered"]Hello member![/groups_member]'
);
?>
Here is a more complex example that shows some text and the login form for those who are not logged in:
<h1><?php _e( 'Welcome', 'example' ); ?></h1>
<?php
$login_content = sprintf(
'[groups_non_member group="Registered"]<p>%s</p>[groups_login][/groups_non_member]',
__( 'Please log in:', 'example' )
);
echo do_shortcode( $login_content );
?>
