Displaying a page built with Elementor using the REST API [closed]

you can create a new endpoint with the following code and you can retrieve the elementor content on URL wp-json/MyPlugin/v1/pages/PAGE_ID/contentElementor

add_action("rest_api_init", function () {

    register_rest_route(
          "MyPlugin/v1"
        , "/pages/(?P<id>\d+)/contentElementor"
        , [
            "methods" => "GET",
            "callback" => function (\WP_REST_Request $req) {

                $contentElementor = "";

                if (class_exists("\\Elementor\\Plugin")) {
                    $post_ID = $req->get_param("id");

                    $pluginElementor = \Elementor\Plugin::instance();
                    $contentElementor = $pluginElementor->frontend->get_builder_content($post_ID);
                }


                return $contentElementor;

            },
        ]
    );


});

Leave a Comment