• Hello,

    I have a function in a plugin that uses wp_send_json to send JSON content to the browser.

    That function works perfecctly in 2022 theme, but any others. 2022 theme is a block theme, so when calling wp_send_json, it can send the header Content-Type: application/json;. whe using non-block theme, header is already sent so wp_send_json does not send that content type header.

    Anyone knows how to do this in a non-block template?

    Jaime

    • This topic was modified 2 years, 6 months ago by jstuardo.
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    You’re probably using it in the wrong context. It has to be used before any output has occurred. It’s normally used in an Ajax response context. Themes aren’t normally involved at all unless your Ajax handler somehow invokes them. Block themes are not template based, their output is handled differently, so you can get away with some things that cause an issue with conventional themes.

Viewing 1 replies (of 1 total)
  • The topic ‘wp_send_json function does not work for non-block themes’ is closed to new replies.