I’m currently working at a WordPress Plugin.
It supports shortcode and creates DOM elements, when the shortcode is called.
Now my problem:
I want to identify the elements.
So when the shortcode gets called the first time it should return something like
<div class="myClass-0"></div>
and when it gets called the second time
<div class="myClass-1"></div>
And so on.
Any ideas on this issue?
Thanks for help
Julian.
You could use a static variable. A static variable holds its value globally and is preserved between function calls:
Here’s a demo. It will work in class methods too, of course, though depending on the situation you might be better off using an instance variable.