Skip to content
AtlanticBT Monogram Atlanticbt.com
Menu
December 19, 2011

WordPress 3.3 Shortcode Issue

capabilities covered
Amazon Web Services

If you find yourself scratching your head over why your shortcodes have stopped working in WordPress 3.3, we’ve discovered a funny quirk. Granted, this fix may actually be the right way to call all shortcodes, but previously we’ve been able to lazily call it directly from our functions.php file and no one cared. But, now it seems, with the upgrade, that WordPress 3.3 does care. It requires your add_shortcode() function to be called within their init() hook. Calling it directly after your newly declared shortcode function won’t work anymore.

The lazy method we got away with before:

[php]
function abtcore_shortcode_button( $atts, $content = null ) {
extract( shortcode_atts( array(
‘color’ => ‘blue’
), $atts ) );
return ‘<p>’ . $content . ‘</p>’;
}

add_shortcode( ‘button’, ‘abtcore_shortcode_button’ );
[/php]

The better way that is now required by WordPress 3.3:

[php highlight=”7″]
function abtcore_shortcode_button( $atts, $content = null ) {
extract( shortcode_atts( array(
‘color’ => ‘blue’
), $atts ) );
return ‘<p>’ . $content . ‘</p>’;
}
add_action(‘init’, ‘abtcore_register_my_shortcodes’, 100);
function abtcore_register_my_shortcodes() {
add_shortcode( ‘button’, ‘abtcore_shortcode_button’ );
}
[/php]

Notice the add_action() call on the ‘init’ on line 7. This will properly register your shortcode function when WordPress initiates.

I hope this helps.

capabilities covered
Amazon Web Services

The Atlantic BT Manifesto

The Ultimate Guide To Planning A Complex Web Project

Partner With Us

Ready for modern web technology and a sharp, user-friendly design? We want to give you exactly that. Contact us to get started.

Contact
  • This field is for validation purposes and should be left unchanged.