Discover in this tutorial how to show an always updated number of active members in Restrict Content Pro using a custom shortcode.
One of the advantages of being in OsomCode is that you can suggest tutorials. A few days ago, a subscriber suggested the following:
Hi Nahuai!
I send you a suggestion for a future snippet:
How to create a shortcode to show the number of active RCP users in a text.
The typical: “We are already more than 200 subscribers in the newsletter”, but with Restrict Content Pro.
Is it feasible?
Thanks!
A very interesting idea, don’t you think?
Here’s how to get it:
Instructions to create a shortcode that displays the number of Restrict Content Pro members always up to date
1. Create the shorcode
Imagine that you want to get a text similar to the one proposed, something like this:
Join the more than X subscribers.
Then, add the following code at the end of functions.php or in your functionality plugin:
To see this and another 1097 code snippets of this website, login or subscribe here.
This snippet shows the number of active members of the Restrict Content Pro subscription.
If you look at the code, you’ll see that you’re subtracting ‘1’ from the number of members to be able to say “more than…” with total rigor (my scientist background shows, ;)) and you add the word ‘subscribers’ to save it later.
This way, to get the above sentence you would have to write:
“Join the more than [number_subscribers] .”
This is just an example, but you can adapt it to your liking.
For example:
2. Customize the shortcode
Go one step further and customize the shortcode according to your needs.
Imagine you want to show the exact number of subscribers in a list or similar.
In that case you would remove the subtraction (the ‘-1’) and the word you had added afterwards (since now you want to enter it somewhere else).
The snippet would look like this:
To see this and another 1097 code snippets of this website, login or subscribe here.
3. Insert the shortcode where you want
You can see that the concept is very similar to the tutorial with which you get to display these variable numbers in the home page of Genesis Sample, but with the advantage that you can insert them anywhere on the web thanks to the shortcode.
Just type “[your_shortcode]” where you want it to be displayed.
Important
- If you are using the classic editor, use the HTML tab to insert the shortcode.
- In case you are already using the new 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
Now you know how to insert the number of active Restrict Content Pro members that will always be kept up to date at any point of the website using a shortcode.
In addition, you have seen that with small variations you can customize it to fit your needs 100%.
Now you just have to put it into practice. 😉
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. 😉