Registering Shortcodes, All Already Exist

73 views Asked by At

I'm using a foreach loop to move through an array of shortcodes. In the loop there's a simple check on the array value to see if the shortcode already exists (say, due to a theme already registering it), and registering it if that condition is false.

The conditional for some reason trips for every value regardless of whether it exists or not (checked against 2015, 2014 and various other themes). Where am I going wrong?

$this->shortcodes  = array(
                'button',
                'one_third', ...

Then in the loop:

foreach( $shortcodes as $shortcode ) {

                if( ! shortcode_exists( $shortcode ) )
                    add_shortcode( $shortcode, array( &$this, function_name_for_shortcode ) );
                else
                    echo $shortcode . ' exists; ';

            } // foreach

Output: one_third_last exists; two_third exists ...

0

There are 0 answers