I'm creating my first plugin and it requires some pages with content to functionally work properly.

I was wondering if it is possible to show a message like "Click here to automatically add the required pages for this plugin" in the wordpress plugins area.

So when the user activates the plugin this message will show and if the user clicks the button a function will run that will add the pages necessary.

Any help in direction most appreciated.


1 Answer 1


You can add those without a button:

register_activation_hook( __FILE__, 'my_plugin_install_function');

function my_plugin_install_function()
   //post status and options
    $post = array(
          'comment_status' => 'closed',
          'ping_status' =>  'closed' ,
          'post_author' => 1,
          'post_date' => date('Y-m-d H:i:s'),
          'post_name' => 'Checklists',
          'post_status' => 'publish' ,
          'post_title' => 'Checklists',
          'post_type' => 'page',
    //insert page and save the id
    $newvalue = wp_insert_post( $post, false );
    //save the id in the database
    update_option( 'hclpage', $newvalue );

This function will run when the user installs the plugin. For super smart control you should check if that option already exists and if the id is not 0 (that means failure)

  • Hey ferenyl, Thanks for the response :) I'm aware of the activation_hook but i would prefer to have the option for the user to auto add content or not.. is this possible?
    – Shoebox
    Dec 17, 2011 at 0:29
  • Add a options page and create a form on that page. Send a get variable and check if isset($_GET['createpage']). if it is call a function.
    – ferenyl
    Dec 17, 2011 at 0:35
  • 4
    Do not use the user ID 1. That user might not exist, or s/he might not have the necessary capability. Use the current user instead, but check if that user is allowed to create posts in that post type.
    – fuxia
    Jun 26, 2015 at 5:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.