Create post/page while installing your plugin

<?php
/*
Plugin Name: NHD Test Plugin
Plugin URI: https://nahidacm.wordpress.com
Description: an test plugin
Author: Mahmudur Rahman Nahid
Version: 0.1-alpha
Author URI: http://facebook.com/mahmudur
*/

?>
<?php
register_activation_hook(__FILE__,'nhd_test_install');

function nhd_test_install(){
    global $user_ID;

    $page['post_type']    = 'page';
    $page['post_content'] = 'Put your page content here';
    $page['post_parent']  = 0;
    $page['post_author']  = $user_ID;
    $page['post_status']  = 'publish';
    $page['post_title']   = 'Your Page Title';

    $pageid = wp_insert_post ($page);
}
?>

There, I used

register_activation_hook

It fires when you active your plugin.

another function I used is,

wp_insert_post

which creates a page.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s