Created
January 28, 2021 19:51
-
-
Save karlazz/7faf6458841ec45983e7f974afb6901e to your computer and use it in GitHub Desktop.
Add a rest route to WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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