Tags

,

I want to create a REST endpoint on my WordPress site. This is to be consumed by a computer so I don’t want any HTML in it at all.

In the WordPress architecture the page or post content is put into a template and rendered to the user. This template has all the HTML boilerplate text and includes the header and footer. When these are included WordPress will also inject any CSS or JavaScript that has been queued by the theme or its plugins.

To create a blank endpoint is only necessary to create a blank template and then create a new page that uses that template. Anything you put in that page will be rendered without any boilerplate.

<?php /** * Template Name: Blank Page * https://blog.jamesbayley.com/2015/06/03/how-to-render-a-blank-wordpress-page */ ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php endif; ?>
Advertisements