最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

frontpage - Set static page as default front page on newly created sites in multisite

programmeradmin2浏览0评论

How to set a Static page (example Sample Page with every WordPress install) as default fron page for every newly created site on multisite network. I mean when a new user creates a site on my multisite network a Page with custom name sets as front page automatically. Please tell me how to accomplish that.

How to set a Static page (example Sample Page with every WordPress install) as default fron page for every newly created site on multisite network. I mean when a new user creates a site on my multisite network a Page with custom name sets as front page automatically. Please tell me how to accomplish that.

Share Improve this question asked Jul 13, 2013 at 12:10 SherrySherry 91 silver badge2 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 1

Try the following code. Based on these two Q&A's (not tested):

  • How to add Custom Blog Options to new blog setup form?

  • Programmatically set page_on_front

add_action( 'wpmu_new_blog', 'process_extra_field_on_blog_signup', 10, 6 );

function process_extra_field_on_blog_signup( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
    switch_to_blog($blog_id);
    $homepage = get_page_by_title( 'Sample Page' );   
    if ( $homepage )
    {
        update_blog_option( $blog_id, 'page_on_front', $homepage->ID );
        update_blog_option( $blog_id, 'show_on_front', 'page' );
    }
    restore_current_blog();
}

Use it as a Must Use plugin.

Be carefull, wpmu_new_blog is deprecated. Use wp_insert_site instead. To give a proper overview, the question can now be answered as follow:

function process_extra_field_on_blog_signup( $new_site ) {
    $blog_id = $new_site->blog_id;
    switch_to_blog($blog_id);
    $homepage = get_page_by_title( 'Sample Page' );   
    if ( $homepage )
{
    update_blog_option( $blog_id, 'page_on_front', $homepage->ID );
    update_blog_option( $blog_id, 'show_on_front', 'page' );
}
restore_current_blog();

}
add_action( 'wp_insert_site', 'process_extra_field_on_blog_signup', 10, 6 );

Wordpress provides a function update_option to set static page programmatically by default when a new blog is created in network multisite.

function my_new_blog_settings($blog_id, $user_id) {

    // set static front page in general settings
    update_option( 'show_on_front', 'page', true);

    // set the static page based on page ID 
    update_option( 'page_on_front', $page_id, true);
}

Above given code can be invoked using action 'wpmu_new_blog'

add_action('wpmu_new_blog', 'my_new_blog_settings', 10, 2);

1) To set Your first page you can add new page as home.php in your directory. Wordpress by default take home.php as its first page if it is declared.

2) Go to settings->Reading->Front page display. You can set here your front page which will display when your site open.

发布评论

评论列表(0)

  1. 暂无评论