I am looking to create a headless WordPress + React website. So far, I have successfully set up the "non-gutenberg" elements like the header and footer. Everything seems to be working fine on that front.
However, I am facing an issue with the styling of the posts content. I am able to retrieve the HTML styling from the JSON and apply it in React, which displays correctly on the frontend.
My dilemma lies in where to place the CSS for gutenberg. I want it to work seamlessly in the Gutenberg editor on the backend as well as on the frontend.
Here is an example of the JSON:
"content": {
"rendered": "\n<p class=\"has-text-color has-accent-color\">Some Random lorem ipsum in a paragraph</p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img src=\"http://bw.dev.local/wp-content/uploads/2020/05/Toronto.jpg\" alt=\"\" class=\"wp-image-13\" srcset=\"http://bw.dev.local/wp-content/uploads/2020/05/Toronto-1024x288.jpg 1024w, http://bw.dev.local/wp-content/uploads/2020/05/Toronto-300x84.jpg 300w, http://bw.dev.local/wp-content/uploads/2020/05/Toronto-768x216.jpg 768w, http://bw.dev.local/wp-content/uploads/2020/05/Toronto-1536x432.jpg 1536w, http://bw.dev.local/wp-content/uploads/2020/05/Toronto-1200x338.jpg 1200w, http://bw.dev.local/wp-content/uploads/2020/05/Toronto.jpg 1920w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" /></figure>\n",
"protected": false
},
While I am sending the classes like has-text-color
, has-accent-color
, etc with the JSON data, I would prefer not to duplicate the CSS styling for both the frontend and backend.
Is there a solution where one set of CSS rules can cater to both aspects?