I'm getting page content via calling /wp-json/v2/page/ And there is no one field with CSS styles. How could I add css styles into json response ? Maybe exist some plugin, which can add custom field ?.. something like this https://wordpress.org/plugins/wp-api-yoast-meta/ will be nice

  • 1
    Why would there be CSS in an API response? Seems like there's a misunderstanding of what the API is and what it's for here... – Jacob Peattie Jun 21 '18 at 11:42
  • 2
    so , there is no way to get css content? only html ? – Алексей Самойлич Jun 21 '18 at 11:47
  • 1
    No. That's not how any of these things are supposed to work. CSS is for presentation and is the responsibility of the site doing the output. If certain styles are required for the output to be rendered properly then you should either find that CSS and just give it to them to add to their site, or structure the data differently so that it uses distinct fields rather than lots of custom markup. – Jacob Peattie Jun 21 '18 at 12:00

CSS of what?

CSS can be relevant only in the context of the full page, and as long as you do not request data for the full page (which you can easily do by just fetching the page and parsing it for the relevant style rules) you lack context. There is simply no such thing as a CSS of a post. Posts can appear in many contexts and in each of them have different styling.

So it is not so much an issue with a technical way to do that, as more of the fact that the requirement itself do not make much sense in context of an API that is supposed to bring data on a single post without any hint of a context.


Mark's answer is correct about having no CSS in the API output. However, if you need to get the URL of your CSS file for any reason, you can add a custom rest route and output it's URI.

Here's a simple code that goes into your theme's functions.php file:

// Register a new rest route
add_action( 'rest_api_init', 'my_rest_routes' );

function my_rest_routes() {

            'methods'  => 'GET',
            'callback' => 'output_css_callback',

// Callback function to output the css URI
function output_css_callback() {
    return get_stylesheet_uri();

Now, you can get the stylesheet's URI dynamically by accessing the below address:


However there's not much point in outputting the main stylesheet's URI, since you probably already know where it's located, but it can be used to output any URI, including custom JS and CSS files.

  • Any idea how to do this for wpgrapql? – Antarr Byrd Aug 6 '20 at 14:32

One solution is getting the stylesheet links and adding it to head in the app that you are using. Or get the complete document.

Explained in detail in the link below.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.