WordPress homepage setup not working on first load

I have a multiste installation that setups a site on user registration, logs them into their new site and then redirects them to their new site’s homepage. This works perfectly however I have a strange homepage setup issue:

When I try and set the homepage using the following:

/** Homepage Setup **/
if (!current_user_can( 'manage_options' )) {
$homepage = get_page_by_title( 'home' );

if ( $homepage )
{
    update_option( 'page_on_front', $homepage->ID );
    update_option( 'show_on_front', 'page' );
}
}
}

in the multisite site’s functions file the user is not initially taken through to this page, instead they are initially shown the default hello world post on first site load instead of the templated homepage as setup above. Strangely if the user reloads the page the homepage is then set correctly. It looks as if the function is not loading when the user is initially redirected to the site, i.e. it is running the setup after the first page has been loaded however this doesn’t seem to make sense to me as other sections of that functions file run. Does anyone have any idea of what might be going wrong here?

Read more here: WordPress homepage setup not working on first load

Leave a Reply

Your email address will not be published. Required fields are marked *