Check wordpress shortcode is exists on home page

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?

Related posts

Leave a Reply

1 comment

  1. 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!!!";
    }