首页 > 解决方案 > Wordpress - 激活插件后添加页面

问题描述

我目前正在制作一个 Wordpress 插件,但我找不到答案。

激活插件后如何添加页面?

我之前使用wp_insert_post函数在激活时添加了帖子,但我找不到插入页面的方法。

标签: phpwordpress

解决方案


您应该使用插件的激活钩子,以便在插件激活时执行任何操作。

register_activation_hook( __FILE__, 'activation_hook_callback');

function activation_hook_callback()
  {
   //add the post type and other options in the array for the query
    $page = array(

          'post_status' => 'publish' ,
          'post_title' => 'Page name',
          'post_type' => 'page',
    );  
    //add the page and ID will be saved.
    $the_page_itself = wp_insert_post( $page );

  }

这应该有效。


推荐阅读