Custom shortcode being executed when saving page in wp-admin

Shortcodes must return, not echo or print their output. As the Codex entry for add_shortcode() explains:

Note that the function called by the shortcode should never produce output of any kind. Shortcode functions should return the text that is to be used to replace the shortcode. Producing the output directly will lead to unexpected results. This is similar to the way filter functions should behave, in that they should not produce expected side effects from the call, since you cannot control when and where they are called from.

Change your shortcode callback function to return its value.

Leave a Comment