11 July 2020

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 );
    }
}

No comments:

Post a Comment

How to create youtube videos slider with play and pause option in wordpress?

Create youtube videos slider with play and pause option in wordpress youtube videos slider Use this shortcode:- [punjab_today] function my_...