Discover with this tutorial how to display the Restrict Content Pro membership level of the logged in user on any website thanks to a shortcode.
One of the advantages of being an OsomCpde subscriber is that you can make suggestions for new tutorials.
The other day, following the tutorial where I explained how to show the name of the person who is logged in, a subscriber suggested that I could also show the Restrict Content Pro membership level. Something like this:
Hello username! You have the “Gold” plan.
Interesting proposal, isn’t it?
If you also want to place personalized messages to your subscriber at certain points on the website, here’s how to do it by combining the wp_get_current_user()
and rcp_get_customer_membership_level_names()
functions in a WordPress shortcode.
Steps to display Restrict Content Pro
1. Create the shortcode
Add the following code at the end of functions.php or in your functionality plugin:
To see this and another 997 code snippets of this website, login or subscribe here.
With this code you create a shortcode that allows you to display the Restrict Content Pro membership level of the logged in user by typing [rcp_membership_level].
If you want the shortcode to display the whole sentence you can use this snippet instead of the previous one:
To see this and another 997 code snippets of this website, login or subscribe here.
Obviously, you can customize the message to your liking.
Now there is only one step left.
2. Insert the shortcode where you want
The advantage of shortcodes is that you can insert them anywhere on the website.
Just type “[your_shortcode]” where you want it to be displayed, in this case [rcp_membership_level].
Important
- If you are using the classic editor, use the HTML tab to enter the shortcode.
- In case you are already using the WordPress block editor you can add it to the normal paragraph block, the HTML block or the shortcode block. All of them will render the content correctly.
Conclusions
You can see how easy it is to show the membership level of a logged in user anywhere on the web thanks to this custom shortcode.
Any questions? I read you in the comments.
And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉