skip to Main Content

I am using the WordPress REST API to retrieve the rendered content of a wordpress page.
My page is constructed with Elementor. And Elementor is adding some inline CSS on the finale page to make all work. This inline CSS is not present in
the content returned by the API.

Example call:

http://website.com/guide/wp-json/wp/v2/pages/23412

Response:

<h1>My title</h1>

Real page HTML:

<h1>My title</h1> <style>h1 { color: red; }</style>

Part am I looking for (not present in the response):

<style>h1 { color: red; }</style>

Do you know how I can retrieve the inline CSS generated by Elementor with the WordPress API ?

2

Answers


  1. Chosen as BEST ANSWER

    The solution described here works pretty well : https://wordpress.stackexchange.com/questions/292849/displaying-a-page-built-with-elementor-using-the-rest-api/292895

    Once the HTML recieved you can parse the page and get the <style> tag with all the Elementor generated inline CSS.


  2. Here is a pretty simple way to get the content of an Elementor into a variable along with styles, I used this to display a single page on all subdomains of a multisite.

    https://wordpress.stackexchange.com/questions/307783/echoing-elementor-page-content-in-template-but-it-doesnt-get-styles-and-some-w

    I’ll add on my own that this code worked for me (with the second argument true)

    $pluginElementor = ElementorPlugin::instance();
    $contentElementor = $pluginElementor->frontend->get_builder_content($post_ID, $with_css = true);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search