Like Us Like Us Facebook Subscribe Subscribe us YouTube Whatsapp Share us Whatsapp Query Send your queries

Create a wordpress page programmatically and Assign Elementor Full Width Template

Create a wordpress page programmatically and Assign Elementor Full Width Template

With the help of  code given below, you can create dynamic page programitically in Word press. In this tutorial, I will create post programitically and assign elementor’s Full width Template.

create a wordpress page programmatically

Create a wordpress page programmatically and Assign Elementor Full Width Template Code:

add_action('init', 'codentricks_create_pg',"");
function codentricks_create_pg($value){
$assignE=sanitize_text_field($_POST['assignE']);
$wordpress_page = array(
'post_title' => $value,
'post_content' => '<h1>Content will be updated soon</h1>',
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'page'
);
//wp_insert_post( $wordpress_page );

$new_page_id = wp_insert_post( $wordpress_page );

if($assignE=='Elementor'):

if( defined( 'ELEMENTOR_VERSION' ) ) //-- if FREE version of Elementor plugin is installed
{
update_post_meta( $new_page_id, '_elementor_version', ELEMENTOR_VERSION );
update_post_meta( $new_page_id, '_wp_page_template', 'elementor_header_footer');
update_post_meta( $new_page_id, '_elementor_edit_mode', 'builder' );
update_post_meta( $new_page_id, '_elementor_template_type', 'wp-page' );
}

if( defined( 'ELEMENTOR_PRO_VERSION' ) ) //-- if PRO version of Elementor plugin is installed
{
update_post_meta( $new_page_id, '_elementor_pro_version', ELEMENTOR_PRO_VERSION );
update_post_meta( $new_page_id, '_wp_page_template', 'page-fullwidth.php' ); //-- for using full width template
update_post_meta( $new_page_id, '_elementor_edit_mode', 'builder' );
update_post_meta( $new_page_id, '_elementor_template_type', 'wp-page' );
}

endif;
// action ends
if(isset($_POST['codentrick_submit'])){
echo '<div class="card">';
$field_values_array = $_POST['field_name'];
$i=1;
$msg="";
foreach($field_values_array as $value){
//echo $value;
$value=sanitize_text_field($value);
if($value!=""){
codentricks_create_pg($value);
$msg.=$i." ". $value."<br/>";
$i++;
}
}
echo "<strong>Created Pages :</strong><br/>".$msg;
echo '</div>';
}

Create a wordpress page programmatically and Assign Elementor Full Width Template HTML Code:

<form action="" method="post">
<div class="field_wrapper">
<div style="margin-bottom:5px;">
<input type="text" name="field_name[]" value="" class="codeField" placeholder="Page Title" autofocus/>
<a href="javascript:void(0);" class="add_button" title="Add field"><i class="dashicons dashicons-insert"></i></a>
</div>
</div>
<div class="buttonCode">
<div style="margin-bottom:10px;">
<select name="assignE" id="assignE" required>
<option value="">Select Option</option>
<option value="None"> WordPress Defult Editor</option>
<option value="Elementor">Elementor (Full Width)</option>
</select>
</div>
</div>
<div class="buttonCode">
<input type="submit" name="codentrick_submit" class="button button-primary" value="Create Pages">
</div>
</form>

You can use this code in word press and generate dynamic page and assign pages to WordPress Default Editor or Elementor Full width Template.

If you have and query or suggestion or need assistance  then please contact me, I will reply to fix your problem, if you like our content then you can subscribe to our Youtube channel. If you want to hire me then reach us at our Fiverr.

5 1 vote
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments