Skip to main content

How to create wordpress page with code in wordpress?

Create wordpress page with code in wordpress.Define page template in wp_insert_post.

add_action( 'admin_init', 'mytheme_admin_init' );
function mytheme_admin_init() {
    if ( ! get_option( 'mytheme_installed' ) ) {
        $new_page_id = wp_insert_post( array(
            'post_title'     => 'Blog',
            'post_type'      => 'page',
            'post_name'      => 'blog',
            'comment_status' => 'closed',
            'ping_status'    => 'closed',
            'post_content'   => '',
            'post_status'    => 'publish',
            'post_author'    => get_user_by( 'id', 1 )->user_id,
            'menu_order'     => 0,
            // Assign page template
            'page_template'  => 'template-blog.php'
        ) );

        update_option( 'mytheme_installed', true );
    }
}
In working...........
add_action( 'admin_init', 'mytheme_admin_init' );
function mytheme_admin_init() {
    if ( ! get_option( 'front page' ) ) {
        $new_page_id = wp_insert_post( array(
            'post_title'     => 'front page',
            'post_type'      => 'page',
            'post_name'      => 'front page',
            'comment_status' => 'closed',
            'ping_status'    => 'closed',
            'post_content'   => '',
            'post_status'    => 'publish',
            'post_author'    => 1,
            'menu_order'     => 0,
            // Assign page template
            //'page_template'  => 'template-jassi.php'
        ) );

        update_option( 'front page', true );
    }
 
      if ( ! get_option( 'Contact Us' ) ) {
        $new_page_id = wp_insert_post( array(
            'post_title'     => 'Contact Us',
            'post_type'      => 'page',
            'post_name'      => 'Contact Us',
            'comment_status' => 'closed',
            'ping_status'    => 'closed',
            'post_content'   => '',
            'post_status'    => 'publish',
            'post_author'    => get_user_by( 'id', 1 )->user_id,
            'menu_order'     => 0,
            // Assign page template
            //'page_template'  => 'template-jassi.php'
        ) );

        update_option( 'Contact Us', true );
    }
 
 
      if ( ! get_option( 'About Us' ) ) {
        $new_page_id = wp_insert_post( array(
            'post_title'     => 'About Us',
            'post_type'      => 'page',
            'post_name'      => 'About Us',
            'comment_status' => 'closed',
            'ping_status'    => 'closed',
            'post_content'   => '',
            'post_status'    => 'publish',
            'post_author'    => get_user_by( 'id', 1 )->user_id,
            'menu_order'     => 0,
            // Assign page template
            //'page_template'  => 'template-jassi.php'
        ) );

        update_option( 'About Us', true );
    }
 
 
      if ( ! get_option( 'Privacy Policy' ) ) {
        $new_page_id = wp_insert_post( array(
            'post_title'     => 'Privacy Policy',
            'post_type'      => 'page',
            'post_name'      => 'Privacy Policy',
            'comment_status' => 'closed',
            'ping_status'    => 'closed',
            'post_content'   => '',
            'post_status'    => 'publish',
            'post_author'    => get_user_by( 'id', 1 )->user_id,
            'menu_order'     => 0,
            // Assign page template
            //'page_template'  => 'template-jassi.php'
        ) );

        update_option( 'Privacy Policy', true );
    }
 
 
     if ( ! get_option( 'term and condition' ) ) {
        $new_page_id = wp_insert_post( array(
            'post_title'     => 'term and condition',
            'post_type'      => 'page',
            'post_name'      => 'term and condition',
            'comment_status' => 'closed',
            'ping_status'    => 'closed',
            'post_content'   => '',
            'post_status'    => 'publish',
            'post_author'    => get_user_by( 'id', 1 )->user_id,
            'menu_order'     => 0,
            // Assign page template
            //'page_template'  => 'template-jassi.php'
        ) );

        update_option( 'term and condition', true );
    }
 
 
   if ( ! get_option( 'Test' ) ) {
        $new_page_id = wp_insert_post( array(
            'post_title'     => 'Test',
            'post_type'      => 'page',
            'post_name'      => 'Test',
            'comment_status' => 'closed',
            'ping_status'    => 'closed',
            'post_content'   => '',
            'post_status'    => 'publish',
            'post_author'    => get_user_by( 'id', 1 )->user_id,
            'menu_order'     => 0,
            // Assign page template
            //'page_template'  => 'template-jassi.php'
        ) );

        update_option( 'Test', true );
    }
}

Comments

Popular posts from this blog

How to use inner html value or data in php from javascript(innerHTML)?

 use inner html value or data in php from javascript(innerHTML)? <html> <body> <p id="demo">use inner html value in php(innerhtml)</p> <script>   var jassi = document.getElementById("demo").innerHTML;   //document.write(jassi); </script> <?php $jassi = '<script>document.write(jassi);</script>'; echo $jassi; ?> </body> </html>

How to get store data from WCFM(Best Multi Vendor Marketplace) Plugin?

 Get store data from WCFM(Best Multi Vendor Marketplace) Plugin. global $WCFM, $WCFMmp, $wp, $WCFM_Query, $post; $store_id = ''; if ( isset( $attr['id'] ) && !empty( $attr['id'] ) ) { $store_id = absint($attr['id']); } if (  wcfm_is_store_page() ) { $wcfm_store_url = get_option( 'wcfm_store_url', 'store' ); $store_name = apply_filters( 'wcfmmp_store_query_var', get_query_var( $wcfm_store_url ) ); $store_id  = 0; if ( !empty( $store_name ) ) { $store_user = get_user_by( 'slug', $store_name ); } $store_id    = $store_user->ID; } $user_id = $store_id;  $vendor_data = get_user_meta( $user_id, 'wcfmmp_profile_settings', true ); $street_1 = $vendor_data['address']['street_1']; $street_2 = $vendor_data['address']['street_2']; $city     = $vendor_data['address']['city']; $zip      = $vendor_data['address']['zip&#

How to create login with phone number in woocommerce wordpress?

Create login with phone number in woocommerce wordpress. function wooc_extra_register_fields() {?>        <p class="form-row form-row-wide">        <label for="reg_billing_phone"><?php _e( 'Phone', 'woocommerce' ); ?><span class="required">*</span></label>        <input type="text" class="input-text" name="billing_phone" id="reg_billing_phone" value="<?php esc_attr_e( $_POST['billing_phone'] ); ?>" />        </p>            <?php  }  add_action( 'woocommerce_register_form_start', 'wooc_extra_register_fields' );  function wooc_validate_extra_register_fields( $username, $email, $validation_errors ) { if ( isset( $_POST['billing_phone'] ) ) {    $hasPhoneNumber= get_users('meta_value='.$_POST['billing_phone']);    if ( !empty($hasPhoneNumber)) {      $validation_er