Skip to content

Instantly share code, notes, and snippets.

@karlazz
Created January 28, 2021 19:51
Show Gist options
  • Save karlazz/7faf6458841ec45983e7f974afb6901e to your computer and use it in GitHub Desktop.
Save karlazz/7faf6458841ec45983e7f974afb6901e to your computer and use it in GitHub Desktop.
Add a rest route to WordPress
//Jack Johannson at https://wordpress.stackexchange.com/questions/306609/how-can-i-fetch-css-from-json-wp-rest-api-response
// syntax for use: http://example.com/wp-json/alexi/v1/output_css_uri
// Register a new rest route and create callback to execute
add_action( 'rest_api_init', 'my_rest_routes' );
function my_rest_routes() {
register_rest_route(
'alexi/v1',
'/output_css_uri/',
[
'methods' => 'GET',
'callback' => 'output_css_callback',
]
);
}
// Callback function to output the css URI
function output_css_callback() {
return get_stylesheet_uri();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment