Reputation: 109
Is there any way to know specific shortcode is applied on specific page?
for e.g. On any WP Theme's home page if related_products shortcode is applied then I want to check it in my plugin file that is applied or not? Is there any way?
Upvotes: 1
Views: 3519
Reputation: 9951
You can use has_shortcode()
to check if your shortcode is applied. If you need to specifically check if it is used on the home page, you can add the is_home()
check
global $post;
if( is_home() && has_shortcode( $post->post_content, 'related_products') ) {
echo "YEAH, shortcode is applied on home page";
}else{
echo "Houston, we have a problem!!!";
}
Upvotes: 4