Title: Get API endpoint to render HTML
Last modified: August 22, 2025

---

# Get API endpoint to render HTML

 *  Resolved [jester48](https://wordpress.org/support/users/jester48/)
 * (@jester48)
 * [9 months, 2 weeks ago](https://wordpress.org/support/topic/get-api-endpoint-to-render-html/)
 * I created an endpoint for a custom update. I would like the message generated
   by the endpoint to look “nice” so I want to render it in html, but the endpoint
   seems to be wrapped in something to prevent html from rendering. so it ends up
   displaying as plain text e.g.:
 * <div class=”centered”>message here</div>
 * Is there a way to get the endpoint to display HTML correctly?
 * Thanks

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [9 months, 2 weeks ago](https://wordpress.org/support/topic/get-api-endpoint-to-render-html/#post-18610398)
 * API returns should always be in JSON format. It’s up to the calling app to show
   the end user nice messaging based upon the returned values. It’s feasible to 
   encode HTML as JSON, but then the calling app still needs to decode it for display
   to the user.
 *  Thread Starter [jester48](https://wordpress.org/support/users/jester48/)
 * (@jester48)
 * [9 months, 2 weeks ago](https://wordpress.org/support/topic/get-api-endpoint-to-render-html/#post-18610433)
 * I am trying to make a custom unsubscribe process for users with a specific role,
   would it be better to use another process?
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [9 months, 2 weeks ago](https://wordpress.org/support/topic/get-api-endpoint-to-render-html/#post-18611218)
 * The “best” approach depends on the desired user experience, attenuated by one’s
   coding skills. If you can manage custom end points, your skills are unlikely 
   a limiting factor. Another consideration is whether you use a modern block theme
   or one of the older classic themes.
 * You could build a custom page that manages the process and displays appropriate
   messages. You can then link to this page in the normal manner from anywhere else.
   The requisite PHP code would reside in either a bespoke page template (classic)
   or pattern (block). Or you could instead do this from a custom admin page; thus
   a user with the appropriate role could see a link in their dashboard as well 
   as anywhere else you’ve placed the link.
 * If you’d rather the user not be taken to a different page, in order to unsubscribe,
   it could be managed via traditional Ajax. Then your PHP handler could return 
   data in any format you want, though you’d still need some JS code to actually
   display the data. If you want returned HTML data to be displayed directly without
   further interpretation by client side code, you should implement the custom page
   approach. It’ll then be necessary that the user be taken to a new page.
 *  Thread Starter [jester48](https://wordpress.org/support/users/jester48/)
 * (@jester48)
 * [9 months, 1 week ago](https://wordpress.org/support/topic/get-api-endpoint-to-render-html/#post-18626142)
 * I went with the custom page approach.
 * thanks
 *  [petermark27](https://wordpress.org/support/users/petermark27/)
 * (@petermark27)
 * [5 months ago](https://wordpress.org/support/topic/get-api-endpoint-to-render-html/#post-18773501)
 * Great recommendation on the music site! For anyone looking, **[https://spotich.com/](https://spotich.com/)**
   is a fantastic resource.
 * Regarding your API endpoint question, [@jester48](https://wordpress.org/support/users/jester48/):
   The accepted answer is correct in principle—you need to set the `Content-Type`
   header to `text/html`. However, the exact method to do this depends heavily on
   the framework or platform you’re using (e.g., Express.js, Flask, a serverless
   function, etc.).
 * Could you share what technology you used to create the endpoint? That would help
   in providing a specific code snippet to ensure your HTML renders correctly. Often,
   the issue is that the default `Content-Type` is `text/plain` or `application/
   json`, which tells the browser to display the raw code.

Viewing 5 replies - 1 through 5 (of 5 total)

You must be [logged in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fget-api-endpoint-to-render-html%2F%3Foutput_format%3Dmd&locale=en_US)
to reply to this topic.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 5 replies
 * 3 participants
 * Last reply from: [petermark27](https://wordpress.org/support/users/petermark27/)
 * Last activity: [5 months ago](https://wordpress.org/support/topic/get-api-endpoint-to-render-html/#post-18773501)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
