You probably don’t need do_shortcode()

Konstantin Kovshenin brought up a good point on his blog, that we should be avoiding do_shortcode() if we can easily use the callback directly. Using the callback function directly prevents WordPress from invoking the shortcode regex that parses shortcode strings. This definitely makes sense when using shortcodes within the theme or plugin they are created in. However, I am a little weary of using these cross-project, as theoretically a developer could change the name of their callback, even though that’s unlikely.

Similar Posts

One Comment

  1. Thanks for sharing this Brian!

    I am a little weary of using these cross-project, as theoretically a developer could change the name of their callback.

    True, but if you’re not sure about the callback function, you can always get find it by its shortcode tag in the $shortcode_tags global and invoke it with call_user_func.

Comments are closed.