[英]Wordpress Sidebar on Widget Section is not displaying upon Custom Plugin Activation
[英]Wordpress - Add a page upon activation of plugin
您應該對插件使用激活掛鈎,以便在激活插件時執行任何操作。
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 );
}
這應該工作。
我解決了 WordPress有幾種post-types
:
Post (Post Type: 'post')
Page (Post Type: 'page')
Attachment (Post Type: 'attachment')
Revision (Post Type: 'revision')
Navigation menu (Post Type: 'nav_menu_item')
要在激活我的插件時添加帖子:
function add_page_upon_activation() {
$arr = array(
'post_title' => 'title',
'post_name' => 'slug',
'post_status' => 'publish',
'post_type' => 'page',
'post_content' => 'yes, a nice page',
);
wp_insert_post($arr);
}
add_action( 'activated_plugin', 'add_page_upon_activation' );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.