Search code examples
wordpressshortcode

What to do if a shortcode already exists


I'm writing a Worpress plugin that defines a shortcode. What happens at shortcode registration if there's another shortcode already registered with that same name ? What is the practice ? Is there a possibility to find the conflicting plugin so as to warn the user that he should deactivate it to be able to activate yours ??

Thanks.

if ( !shortcode_exists( 'myshortcode' ) ) {
    add_shortcode('myshortcode','mycallback');
}
else ?????

Solution

  • The best practice is allways to prefix the name of your shortcode in order to avoid naming collisions. You can use a particular prefix in relation with your plugin name or activity. You can see some guideline in the plugins development handbook here : https://developer.wordpress.org/plugins/the-basics/best-practices/#prefix-everything

    My personal practice is to process with a personal name spacing format. It could give something like:

    add_shotcode('company_plugin_shorcode');
    

    Hope it helps