Discover with this tutorial how to display the number of months of seniority or loyalty of a Restrict Content Pro subscriber anywhere on the web thanks to a shortcode.
One of the advantages of being an OsomCode subscriber is that you can make suggestions for new tutorials.
The other day, following the tutorial on how to calculate and display the loyalty months of a subscriber in Restrict Content Pro, one of you suggested me to prepare a tutorial in which this data could be displayed anywhere on the web.
That is, it should be visible not only in the administration side WordPress but also in the frontend.
An interesting proposal, right?
Showing this data to subscribers can be rewarding or motivating them. In fact, you can combine it with the tutorial to show the name of the logged in user and display something like this:
Good morning, Miguel! Thank you for being part of the project for 18 months.
Good morning, Miguel! Your loyalty level is: 18 months.
Or any other combination you can think of.
Steps to display the username using a shortcode
1. Apply the tutorial that calculates the loyalty months
In order to display the number of months you first have to follow the tutorial on how to calculate and display the loyalty months of a subscriber in Restrict Content Pro.
This first step is the one that takes care of creating a new metadata for each subscriber with the months of seniority.
2. Create the shortcode to show the subscriber loyalty
Add the following code at the end of functions.php or in your functionality plugin:
With this code you create a shortcode that allows you to show the months that have been subscribed when typing
Now there is only one step left.
3. Insert the shortcode where you want
The advantage of shortcodes is that you can insert them anywhere on the website.
You only have to type “[your_shortcode]” where you want it to be displayed, in this case
- If you are using the classic editor, use the HTML tab to insert the shortcode.
- In case you are already using the new block editor (Gutenberg) you can add it to the normal paragraph block, the HTML block or the shortcode block. All of them will render the content correctly.
You can see how easy it is to display the loyalty months of a Restrict Content Pro subscriber anywhere on the web thanks to this custom shortcode.
Any questions? Let me know 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. 😉