Search
Close this search box.

How to check if shortcode already exists in WordPress

To check if a shortcode already exists in WordPress, you can use the has_shortcode() function. This function checks if the specified shortcode exists in the provided content.

Here’s an example of how to use this function:

// How to check if shortcode already exists
// More snippets at wpunplugged.com 

if ( has_shortcode( $content, 'my_shortcode' ) ) {
    // shortcode exists, do something
} else {
    // shortcode does not exist, do something else
}

You can also use the shortcode_exists() function to check if a shortcode has been registered with WordPress. This function takes the shortcode name as an argument and returns a boolean value indicating whether the shortcode exists.

Here’s an example of how to use this function:

// How to check if shortcode already exists
// More snippets at wpunplugged.com 

if ( shortcode_exists( 'my_shortcode' ) ) {
    // shortcode exists, do something
} else {
    // shortcode does not exist, do something else
}

Both of these functions can be used in your theme’s functions.php file or in a plugin.

Share this post

You might also like...

UpdraftPlus for WordPress Review
Backup

UpdraftPlus for WordPress Review

UpdraftPlus for WordPress is a powerful backup plugin that enables users to easily back up their website’s content, including the WordPress database, themes, plugins, and

Read More »
WP Rocket for WordPress Review
Cache

WP Rocket for WordPress Review

WP Rocket is a popular WordPress plugin that offers comprehensive caching and optimization solutions for WordPress websites. It is designed to help improve website performance,

Read More »

Comment

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