我想编写一个插件并在页面中放置一些html控件,这些控件将在用户安装插件时自动创建
基于该注释,您希望将函数挂钩到插件的激活挂钩,该挂钩将WordPress发布对象插入到数据库中;
function my_plugin_activate()
{
wp_insert_post(array(
'post_type' => 'page',
'post_title' => 'Page Title',
'post_content' => 'Page Content',
'post_name' => 'page-slug',
));
}
register_activation_hook(__FILE__, 'my_plugin_activate');
Run Code Online (Sandbox Code Playgroud)
你将如何识别page
?假设你有一个特定的标题,使用类似
if( get_page_by_title('my_title') === false ) // page doesn't exist
{
// insert the page using wp_insert_post
}
Run Code Online (Sandbox Code Playgroud)
如果您需要有关 wp_insert_post 的帮助,请发表评论。