1

Is it expected behavior that the callback of a shortcode is executed even if the result isn't returned, or do shortcodes only execute when they are displayed?

1
  • the shortcode is executed when he is in the content of a post, even if it displays nothing.
    – Kaperto
    Commented Nov 28, 2019 at 13:24

1 Answer 1

1

Shortcode callbacks are not executed unless the shortcode is parsed and executed. So if a shortcode has been added, its callback will not run unless the shortcode has been used somewhere on the page, or executed manually in a function or template that has been used, and it will only be run at the moment that the shortcode is parsed.

So the act of registering a shortcode with add_sortcode() alone will not execute the callback function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.