I’m using do_shortcode
function to add shortcode in my template. But i would like to check if that shortcode exists before display them.
I mean like this
If (shortcode_gallery_exists) {
echo do_shortcode('');
}
Can anyone help me? Thanks
I’m using do_shortcode
function to add shortcode in my template. But i would like to check if that shortcode exists before display them.
I mean like this
If (shortcode_gallery_exists) {
echo do_shortcode('');
}
Can anyone help me? Thanks
You must be logged in to post a comment.
#23572 introduced shortcode_exists() into 3.6.
I think you could use the following code to do this:
(Caveat: not tested)
Found this online somewhere and used is once or twice
.
(i know the [gallery is missing the ].. leave it like so)
This should be used inside the loop
..
Hope this helps, Sagive
You can create your own function,
The in your template write a conditional like,
Idea from this NetTuts link
WP now has a built-in function for this:
https://developer.wordpress.org/reference/functions/shortcode_exists/
WordPress allows you to check whether a shortcode exists or not.
To check it you can use
shortcode_exists()
function. It returns true if the shortcode exists.Where
$tag
is the name of shortcode you want to check.I know it’s old question but someone may still need this, especially because
shortcode_exists()
may not work for some plugin shortcodes: