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 : wpinsert_post()


// 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' );


  1. avatar
    wrote this comment on

    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?


  2. avatar
    wrote this comment on

    This code is intended for plugin authors. You should use the usual settings page, settings->reading.

  3. avatar
    wrote this comment on

    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?

  4. avatar
    wrote this comment on

    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 :-)

  5. avatar
    wrote this comment on

    I am assuming this goes into functions.php, but where could it be placed to just fire once, on first install of a theme?

  6. avatar
    wrote this comment on
    Oops, looks like I forgot to answer your question. For a theme you'll want to implement your own activation hook, as WordPress doesn't have one. I think the easiest would be to add a 'theme_setup' option or somesuch that you check on each pageload. But doing this doesn't sound ideal.
  7. avatar
    wrote this comment on
    I administer a community website in the UK. I am currently using Seashore as our theme which has three columns. We would like to make the site member-ship only and I think that WP-Members would be fine to get viewers and contributors to register and login. However, WPM is based upon Twenty Ten and Twenty Eleven so when I activate it the registration form bleeds into my theme columns. I thought that a splash page would be better and have noticed your code. However I am not a coder. Can you help?
  8. avatar
    wrote this comment on
    Hello Errol, I can certainly help. Please use my contact form if you're interested in hiring me.
  9. avatar
    wrote this comment on
    Hi Nicolas. I've changed my "home" page from posts to static as described in your guide. However, with this change the static page "moved" upwards and is blocking my header pic. Where do I makes changes for the static page to fit properly? Thx.
  10. avatar
    wrote this comment on
    Either the css or the right template, see
  11. avatar
    wrote this comment on
    Is there anyway to have a navigation link in my nav-bar that will point towards the author template page??
  12. avatar
    wrote this comment on
    The nav menu system lets you add links to anything you like. There are also plugins like page-links-to if you don't use the (relatively new) menu system.
  13. avatar
    wrote this comment on
    Hi, maybe you can point me in the right direction for this. I have a WP site, and I'd like to change it to have a NON-WP static front page, that I could use to link to the WP site. Any idea what I'd need to do? Thanks
  14. avatar
    wrote this comment on
    You could simply drop an index.html file into the root directory. Depending on the server configuration it should be displayed by default.
  15. avatar
    wrote this comment on
    I am using the Twenty Eleven theme and have made my home page a static page. I want to change the title and the area where it resides on all the pages to make it smaller in height, to add a logo and slogan under the title and to change the font and its color. I am new to code and do not know where to find the code that allows me to make these changes.
  16. avatar
    wrote this comment on
    Hi, have a look at
  17. avatar
    wrote this comment on
    I set the front page as static and created another page as a blog page for posts. I'm creating a different page for each article I want to publish. I left the blog page blank except for the title as instructed. But I'm confused. I want to make small posts that will appear on the blog page, linking to my article pages. How do I make that happen? Thanks in advance.
  18. avatar
    wrote this comment on
    I like to create the static page in v 3.3.1 but I can't follow the same directions. The dashboard is different. So Q: How can I create static page in this new version? TIA
  19. avatar
    wrote this comment on
    Hi Nicolas, I am a beginner in word press, I want to create a Joomla Site In word press. Also I've not any source code or admin id/password for that site. So Guide me how to create theme & other functionality. thanx.
  20. avatar
    wrote this comment on
    It sounds like you may want
  21. avatar
    wrote this comment on
    It seems as though setting up a static front page has changed in this newest release (3.4.something), and I cannot set up a non post - page only site anymore... what's up with that? HELP!
  22. avatar
    wrote this comment on
    Not sure what you mean?
  23. avatar
    wrote this comment on
    Hi all - Great plugin How can I get event to also be displayed on this theme's "Avenue Theme" carousel on th homepage. For all other posts I tag the post to be "featured" and upload a larger image so it adds it to the homepage carousel. Is this possible with events manager? Any help would be appreciated Also will this work with multsites? Thanking you in advance
  24. avatar
    wrote this comment on
    Chris - I just discovered that if you delete all pages or haven't created one, then the option disappears in WPadmin...
  25. avatar
    wrote this comment on
    Hi Nicolas, tried your code, i can see the pages in dashboard settings but i cannot see the page on my site, and is there any way to specify that the page is a parent page, could you help me with the issue, I am using angular theme, thanks :)
  26. avatar
    wrote this comment on
    Sorry, I don't understand your question.
  27. avatar
    wrote this comment on
    Hi, any ideas why it is not working: [et_widget type="ET_Widget_Recent_Posts" title="News"]
  28. avatar
    wrote this comment on
    No idea what et_widget type is. Certainly not one of my plugins.
  29. avatar
    wrote this comment on
    perfect - just the codeI was looking for thank you...
  30. avatar
    wrote this comment on
    Thanks mate!
  31. avatar
    wrote this comment on
    I am trying to display a different front page, depending on the value of a counter I have tried to implement. But it is not working - can somebody tell me what I am doing wrong? Any help is greatly appreciated. ID ); update_option( 'show_on_front', 'page' ); } elseif ($SignupCounter == 1) : { $LP = get_page_by_path( '/home-1' ); update_option( 'page_on_front', $LP->ID ); update_option( 'show_on_front', 'page' ); } ?>
  32. avatar
    wrote this comment on
    Just for reference there is now a hook for theme activation: after_switch_theme I know this is about 4 years too late for Nick but will prove useful for anyone else who happens across this in future :-)


Cancel reply
Markdown. Syntax highlighting with <code lang="php"><?php echo "Hello, world!"; ?></code> etc.
DjangoPythonBitcoinTuxDebianHTML5 badgeSaltStackUpset confused bugMoneyHackerUpset confused bugX.OrggitFirefoxWindowMakerBashIs it worth the time?i3 window managerWagtailContainerIrssiNginxSilenceUse a maskWorldInternet securityPianoFontGnuPGThunderbirdJenkinshome-assistant-logo