how do I programically create a page in WordPress if it doesn’t exist already?
3条回答 默认 最新
- dpxyfa4718 2010-07-21 12:19关注
I want to write a plugin and to put some html controls in a page which will automatically create when user install the plug in
Based on that comment, you want to hook a function to your plugin's activation hook, which inserts a WordPress post object into the database;
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');
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报