I want to pass some json data to JS from wordpress(PHP) and was thinking to use ob_start() and ob_end_clean() in wordpress but i am not sure weather any other plugins are using the same functions. I was thinking to manually add ob_start() at the beginning of the theme header and clear the document when necessary. I thought of using grep find if there are any ob_start() in wordpress, but i can't grep find everytime my website gets updated. Are there any workarounds? I will be calling ob_end_clean() from a shortcode.

1 Answer 1


WordPress has a whole set of useful functions to handle. It's called wp_send_json(). You have success and error functions too.

ob_start(), ob_get_clean() would be useful in case you want to include some views (~ MVC) in your shortcode, e.g in your shortcode handler. I don't see here why you would use them to pass data from PHP to js.

Otherwise I would use them in the shortcode handler, no use to put them in theme.


Your Answer

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