Set up static page as default

When changing themes, the default home page is set to show archive, please advise how to set static home page from the settings without changing this option from Settings > General.

So the static home page will be selected already after switching theme

  • Panos

    Hi NextSunday ,

    Probably some themes may be changing this option for their needs.

    You can try by overriding this change with this little snippet:

    add_action('after_switch_theme', function(){
    
    	$page = get_page_by_title( 'My page title' );
    
    	update_option( 'page_on_front', $page->ID );
    	update_option( 'show_on_front', 'page' );
    
    }, 999 );

    You need to replace either My page title with the title of your static home page or if you prefer to use the ID, replace $page->ID with the page id.

    You can create a mu-plugin to add this snippet. Go to your wp-content/mu-plugins folder, if that folder doesn't exist simply create it. Inside that folder create a new file, name it eg static-front-page.php or something similar.

    Open to edit that new file. First thing you add is the php tag: <?php then add a new lne and paste the snippet above.

    Hope this helps :slight_smile:

    Cheers!