'How to use wp_insert_post to create a page with Elementor content?
I want to create a page using wp_insert_post but set the page to have Elementor content. Here is the code I have:
// Create post object
$my_post = array(
'post_title' => wp_strip_all_tags( 'Test Page' ),
'post_content' => 'elementor json goes here',
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'page'
);
// Insert the post into the database
wp_insert_post( $my_post );
But when I do this, the content just prints the actual JSON.
Solution 1:[1]
I would create an Elementor template then export it. You then have different options. You can manually import the templates exported into the new website, or set up One Click Demo Import. Popular themes use this plugin to import ready-made templates that used Elementor.
Here is more information about both: https://powerpackelements.com/how-to-save-import-and-export-templates-in-elementor/ https://wordpress.org/plugins/one-click-demo-import/
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | JayDev95 |