Skip to Content
Menu

initialization_create_homepage()

Creates and/or sets a home page.

PHP April 27, 2017

Usage

This function runs automatically, so it is not called manually. Is this incorrect?

Additional Notes

Uses the Sample Page if available, otherwise creates a new home page with an ID of 0.

This function will not override a home page if one exists already.

Was this page helpful? Yes No


    A feedback message is required to submit this form.


    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!

    Source File

    Located in /libs/Admin/Automation.php on line 354.

    No Hooks

    This function does not have any filters or actions available. Request one?
    PHP
            public function initialization_create_homepage(){
                $current_front_page = get_option('page_on_front');
                $sample_page = get_page_by_title('Sample Page');
                if ( empty($current_front_page) || $current_front_page === $sample_page ){
                    $new_homepage_id = ( !empty($sample_page) )? $sample_page : 0;
                    wp_insert_post(array(
                        'ID' => $new_homepage_id,
                        'post_type' => 'page',
                        'post_title' => 'Home',
                        'post_name' => 'home',
                        'post_status' => 'publish',
                        'post_author' => get_current_user_id(),
                    ));
    
                    update_option('page_on_front', get_page_by_title('Home'));
                    update_option('show_on_front', 'page');
                }
            }
    

    Override

    This function can not be short-circuited with an override filter. Request one?