I'm using the WordPress API as a headless CMS. I have Elementor plugin installed to do page building in the WordPress admin.

I'm trying to figure out how to get all of the <link> and <script> tags that Elementor requires via the WordPress API. The API right now for /pages only gives me the rendered HTML from the_content().

Is there a way to extend WordPress API /pages to either:

  • Return the <head> links and scripts and any <body> links and scripts?
  • Return the full HTML for a page, from <html> to </html>?

My backup solution is to use a screen scraping tool to get the full HTML, but I'd rather avoid doing that.

  • 1
    Correct me if I'm wrong, but isn't the point of going headless to separate the content from of the page from the display? It sounds like what you're describing is using WordPress as a CMS and WordPress as a display output with a overly complicated controller in the middle. It would help me to understand the purpose to give advice on how to move forward. – MikeNGarrett Apr 11 at 18:17
  • Yes, that is the point, and I understand that. In this particular case, the website is a PWA and public website. It has a lot of custom functionality handled via React (CRUD-ing) along with some CMS controlled pages. – Zachary Winnie Apr 11 at 18:30
  • Instead of having 50+ small React applications loaded via WordPress page templating, which would be incredibly complex to maintain for the client, the approach is instead one React app that is used to load a handful (12-24) CMS pages. These CMS pages use Elementor to customize their layout. Elementor injects custom CSS and scripts to support its own layout widgets (tabs, accordions, etc). – Zachary Winnie Apr 11 at 18:32
  • 1
    I should also note that we're using a mix of Next.js and React so that CMS pages can retain server-side HTML rendering for SEO. – Zachary Winnie Apr 11 at 18:33
  • I don't have a full answer, but take a look at the Frontend class. – MikeNGarrett Apr 11 at 20:11

Your Answer

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

Browse other questions tagged or ask your own question.