A lightweight WordPress theme designed to function purely as a headless REST API endpoint. It strips away all frontend rendering and traditional WordPress theme features, focusing solely on providing a clean, efficient REST API interface for your WordPress content.
- Lightweight WordPress theme.
- Clean and optimized codebase for API-focused development.
- Removed unnecessary WordPress frontend features.
- Disabled frontend rendering.
- Redirects all frontend requests to the REST API endpoint.
- Clone the repository or download the zip file of this theme.
- (Optional) Rename the theme folder. And to update all theme references, run the provided rename script:
This will automatically update all theme references.
php ./scripts/rename-theme.php "NEW Theme Name"
- Upload the theme to the
wp-content/themes/
directory. - Activate the theme via the WordPress admin panel: Appearance > Themes.
If your API requires authentication, install the following plugin:
- JWT Authentication for WP REST API: This plugin secures your API endpoints with JWT tokens.
Run the following command in the theme directory to install Composer dependencies:
composer install
- Duplicate
.env.example
to.env
:cp .env.example .env
- Replace the
JWT_AUTH_SECRET_KEY
value with a strong random string. You can use this tool to generate one.
Add the following code snippet to your wp-config.php
file:
/* Add any custom values between this line and the "stop editing" line. */
$theme_path = __DIR__ . '/wp-content/themes/rest-api-starter';
if (file_exists($theme_path . '/vendor/autoload.php')) {
require_once $theme_path . '/vendor/autoload.php';
// Load environment variables from .env
$dotenv = Dotenv\Dotenv::createImmutable($theme_path);
$dotenv->load();
define('JWT_AUTH_SECRET_KEY', $_ENV['JWT_AUTH_SECRET_KEY']);
define('JWT_AUTH_CORS_ENABLE', $_ENV['JWT_AUTH_CORS_ENABLE']);
}
/* That's all, stop editing! Happy publishing. */
If this setup doesn’t work, you can hardcode the secret key directly (not recommended for security reasons):
/* Add any custom values between this line and the "stop editing" line. */
define('JWT_AUTH_SECRET_KEY', 'your_secret_key_here');
define('JWT_AUTH_CORS_ENABLE', true);
/* That's all, stop editing! Happy publishing. */
This theme is designed to be used purely as a backend API. Once installed:
- All frontend requests will be redirected to
/wp-json
. - Use the WordPress REST API to interact with your site content.
GET /wp-json/wp/v2/posts
- Retrieve posts.GET /wp-json/wp/v2/pages
- Retrieve pages.GET /wp-json/wp/v2/media
- Retrieve media items.
- Obtain a token:
POST /wp-json/jwt-auth/v1/token { "username": "your-username", "password": "your-password" }
- Use the token for authenticated requests:
GET /wp-json/wp/v2/posts Authorization: Bearer <your-token>
The testing-api
directory contains ready-to-use HTTP request files for testing the API endpoints. These tests are designed to work with VS Code's REST Client extension.
For detailed information about the API tests, see testing-api.md.
For detailed WordPress REST API documentation, visit: WordPress REST API Handbook
This theme is licensed under the GNU General Public License v2 or later (GPL-2.0). See the LICENSE file for details.
For support and contributions, visit the Technway GitHub repository.
The Rest API Starter Theme is built with ❤️ and maintained by Technway.
Contributions are welcome! Feel free to fork the repository and submit pull requests.