添加/移除 WordPress 多站点网络的默认页面

在 WordPress 多站点网络中,只要你新建一个站点,都会自动创建一个默认页面(即“示例页面”)。在某些情况下,这个默认页面不是你想要的,或者说你想修改这个自定义页面的内容,比如引导这个开通站点的用户该做些什么,注意些什么等等。那你可以按照本文教程来实现。

sample-page_wpdaxue_com

将下面的代码添加在主站点的主题的 functions.php 文件或某个特定插件中:

/**
 * 添加/移除 WordPress <a href="https://www.wpdaxue.com/tag/%e5%a4%9a%e7%ab%99%e7%82%b9" title="查看与【多站点】相关的文章" target="_blank" rel="noopener">多站点</a>网络的默认页面
 * https://www.wpdaxue.com/add-remove-default-pages-in-wordpress-multisite.html
 */
add_action('wpmu_new_blog', 'wpb_create_my_pages', 10, 2);
 
function wpb_create_my_pages($blog_id, $user_id){
  switch_to_blog($blog_id);
 
// 创建一个新页面
  $page_id = wp_insert_post(array(
    'post_title'     =&gt; 'About',
    'post_name'      =&gt; 'about',
    'post_content'   =&gt; 'This is an about page. Feel free to edit or delete this page.',
    'post_status'    =&gt; 'publish',
    'post_author'    =&gt; $user_id, // or "1" (super-admin?)
    'post_type'      =&gt; 'page',
    'menu_order'     =&gt; 1,
    'comment_status' =&gt; 'closed',
    'ping_status'    =&gt; 'closed',
 ));  
 
// 查找和删除WordPress默认页面'Sample Page'
//如果是简体中文,你可能需要修改'Sample Page'为'示例页面'
$defaultPage = get_page_by_title( 'Sample Page' );
wp_delete_post( $defaultPage-&gt;ID );
 
  restore_current_blog();
}

上面的第一段代码是创建了一个标题为“About”,内容为“This is an about page. Feel free to edit or delete this page.”的默认页面;第二段是找到并删除标题为“Sample Page”的默认页面。

参考资料:http://www.wpbeginner.com/

来源:

https://www.wpdaxue.com/add-remove-default-pages-in-wordpress-multisite.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_32664.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?