There are several shortcodes that you can use in your post editor or any shortcode-ready area. In the block editor, add them with a Shortcode block or inside a Paragraph block.
[members_access]
The [members_access] shortcode is for hiding content from particular roles and capabilities. You need to wrap your content when using this shortcode:
[members_access role="editor"]Hide this content from everyone but editors.[/members_access]
The plugin accepts the following parameters (mixing and matching won’t work):
role– A single or comma-separated list of roles.capability– A single or comma-separated list of capabilities.user_name– A single or comma-separated list of usernames.user_id– A single or comma-separated list of user IDs.user_email– A single or comma-separated list of user email addresses.
Parameters:
capability: A capability that has been assigned to a role.role: A user role from WordPress or one that you’ve created.operator: Accepts!to negate the role or capability.
Note that capability and role parameters aren’t used in conjunction. The code first checks for the capability (if input) then checks for the role (if input).
To check for multiple capabilities or multiple roles, simply add a comma between each capability/role. For example, the following code checks for an editor or administrator:
[members_access role="administrator,editor"]Show this content to administrators or editors only.[/members_access]
To check that the user does not have a role:
[members_access role="administrator" operator="!"]Show this content to anyone who is not an administrator.[/members_access]
[members_logged_in]
The [members_logged_in] shortcode should be used to check if a user is currently logged into the site. If not, the content will be hidden.
[members_logged_in]This content is only shown to logged-in users.[/members_logged_in]
This shortcode has no parameters.
[members_not_logged_in]
The [members_not_logged_in] shortcode should be used to show content to users who are not logged into the site. If the user is logged in, the content will be hidden.
[members_not_logged_in]This content is only shown to logged-out visitors.[/members_not_logged_in]
[members_login_form]
The [members_login_form] shortcode is used to show a login form on the page.
[members_login_form /]
Parameters:
redirect: The URL to send users to after they log in. If you leave it out, users go back to the page they logged in from.
[members_login_form redirect="https://example.com/welcome/"]
If a login fails, the user comes back to the same page and sees an error message with the form. A wrong username, email address, or password always shows the same message, so the form doesn’t reveal which accounts exist. Messages from security plugins, like a lockout after too many attempts, are still shown.
The form works with two-factor authentication from Wordfence and the Two Factor plugin. Users who have two-factor turned on are asked for their code, just like on the regular WordPress login page.
Good to know:
- Logged-in users don’t see the form. They see “You are already logged in.” To check your form, view the page in a private browser window, or while logged out.
- Use it in the Content Permissions error message. The error message runs shortcodes, so you can show a login form where protected content would be. See Content Permissions.
- Styling: the form adds a little CSS of its own, scoped to
.members-login-form. To change it, add more specific CSS in your theme, for example.entry-content .members-login-form input[type="submit"] { background: #000; }. - Logging out: the form doesn’t include a logout link. The free Login or Logout Menu Item plugin adds a menu link that switches between “Log in” and “Log out”.
- Registration: Members doesn’t include a registration form. WPForms can build user registration forms, and MemberPress includes registration, login, and account pages for membership sites.
To send users to different pages depending on their role, you can use the free LoginWP plugin (formerly Peter’s Login Redirect).
[members_feed]
The [members_feed] shortcode shows its content only in your site’s RSS feed. It’s hidden on the site itself. Use it for a note to feed readers, like “Read the full post on our website.”
[members_feed]Members can read the full post on our website.[/members_feed]
This shortcode has no parameters.