Set static front page and blog page programmatically in WordPress
You want to make sure the About and Blog pages exist, so create them before if necessary, see http://codex.wordpress.org/FunctionReference/wpinsertpost : wpinsert_post()
<?php
// Use a static front page
$about = get_page_by_title( 'About' );
update_option( 'page_on_front', $about->ID );
update_option( 'show_on_front', 'page' );
// Set the blog page
$blog = get_page_by_title( 'Blog' );
update_option( 'page_for_posts', $blog->ID );
// Switch to our theme
//switch_theme( 'Template', 'stylesheet' );
?>
Dear Friend, I´m try to get my posts in my blog page and I saw your code but where can I put this?
Index.php or and different file?
Regards
Frank
This code is intended for plugin authors. You should use the usual settings page, settings->reading.
do you know what hook you would need to connect with to create this static home page? Or does the update_options do this automatically?
Good question. IIRC plugin activations hook fire before init, so I'm not sure if that would be safe.
For themes, no idea, afaik they don't have activation hooks.
I use this code on wpmu_new_blog, but that's probably not what you're looking for :-)
I am assuming this goes into functions.php, but where could it be placed to just fire once, on first install of a theme?