1. WordPress Snippets

Check If Shortcode Already Exists in WordPress

Do you need to check if shortcode already exists in WordPress if you need that you can do it in just one minute using this code snippet.

Steps to check shortcode in WordPress:

  1. Open WordPress admin panel then go to Appearance > Theme Editor
  2. Open theme functions.php file, if you work localhost open the same file using any code editor IDE
  3. Add the following code at the bottom of the file.
  4. Save the changes.
function zytheme_shortcode_exists( $shortcode = '' ) {
  global $shortcode_tags;
  if ( $shortcode && array_key_exists( $shortcode, $shortcode_tags ) ){
      return true;
  }else{
      return false;
  }
}

Add this code on your theme’s index.php file to check if the shortcode already exists.

if(zytheme_shortcode_exists('zytheme_button')){
    echo 'button shortcode exists';
}

Did you find the WordPress snippets in this article helpful? Share it with your friends and if you have any questions and want to ask us about it, please don’t hesitate to add comments.

Comments to: Check If Shortcode Already Exists in WordPress

Your email address will not be published. Required fields are marked *