• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Deeper Scenery

Further up and further in

  • Home
  • Blog
  • Code
  • Tutorials
  • Privacy Policy
You are here: Home / Ideas / Manually Running Shortcodes

Ideas · Published: September 5, 2018 · Modified: September 6, 2018

Manually Running Shortcodes

This is just a small idea. For more information, see this blog post.

Note: the following example is wrong*. Do not do it!

I often see code like the following:

do_shortcode( '[some_shortcode]' );

I want to explain the proper way of manually running shortcodes using PHP.


*Ok, it’s not strictly wrong, it’s just not the best solution all the time.

Filed Under: Ideas

Previous Post: « OOP form library
Next Post: Advanced WordPress Hooks »

Reader Interactions

Comments

  1. Sal Ferrarello says

    September 6, 2018 at 10:38

    If I understand properly you’re advocating calling the underlying function/method instead of calling do_shortcode() to avoid the extra overhead of the regular expression processing of the string that gets passed to do_shortcode();. I agree with this.

    As you mentioned in your tweet, this is definitely better when you’re in control of the shortcode (i.e. it is your own code) though a little less certain when the shortcode is someone else’s (they could change the name of their function/method).

    I’m spitballing here without really thinking it through but it seems one could use the shortcode string to lookup the callable function in the global $shortcode_tags; and then call that function – that could be cool.

    Reply
    • Jeremy says

      September 7, 2018 at 13:34

      Generally speaking, I would indeed advocate for calling the underlying function/method directly where possible. Using the global $shortcode_tags is an idea I hadn’t thought of before, but that’s another good avenue to take.

      Thanks for the feedback, Sal 🙂

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Subscribe to jeremypry.com

Enter your email address to subscribe to this site and receive notifications of new posts by email.

  • Home
  • Blog
  • Code
  • Ideas
  • Tutorial
  • Gifts
  • Privacy Policy

Copyright © 2025 · JPry Showcase Pro on Genesis Framework · WordPress · Log in