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.
1 thought on “You probably don’t need do_shortcode()”
Comments are closed.
Thanks for sharing this Brian!
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 withcall_user_func
.