I'm trying to push some variables to google analytics and would like to be able to detect if a shortcode has been included on a page at all.
Anybody know a smart way going about this?
I have sometimes wondered the same thing - whether wp maybe checked on save and kept a register etc
I had a quick look at the code, and it seems not.
There is however a global
used here to apply the shortcode:
My regex is not that great, but maybe you could do something with that?
Then there is the brute force way - for each of the shortcode tags, 'simply' check if
So then, you could also check the wp global
To be clever
You could maybe add an action yourself on post save/update, do the check for filters and shortcodes then and store something in a post-meta. Then all you have to do at display time is check the post-meta.
Whew... is it worth it?
A simple way, use
So here's my trainwreck version of it (as it stands this minute, Anmari has given plenty of good ideas). It's not really flexible at all for anyone else's use either, but our hosted platform and how people use it is very flexible (makes my life easier):