获取由 Elementor 使用 Wordpress Rest API 生成的内联 CSS



我正在使用Wordpress REST API来检索wordpress页面的渲染内容。 我的页面是用 Elementor 构建的。Elementor正在结局页面上添加一些内联CSS,以使所有工作正常。此内联 CSS 中不存在 API 返回的内容。

调用示例:

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

响应:

<h1>My title</h1>

真实页面 HTML:

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

我正在寻找的部分(未出现在响应中(:

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

你知道我如何使用Wordpress API检索Elementor生成的内联CSS吗?

这里描述的解决方案效果很好: https://wordpress.stackexchange.com/questions/292849/displaying-a-page-built-with-elementor-using-the-rest-api/292895

收到 HTML 后,您可以解析页面并获取带有所有 Elementor 生成的内联 CSS 的<style>标签。

这是一种非常简单的方法,可以将 Elementor 的内容与样式一起放入变量中,我使用它在多站点的所有子域上显示单个页面。

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

我会自己补充一点,这段代码对我有用(第二个参数为 true(

$pluginElementor = ElementorPlugin::instance();
$contentElementor = $pluginElementor->frontend->get_builder_content($post_ID, $with_css = true);

最新更新