Skip to main content
3 of 4
added 4 characters in body
1.21 gigawatts
  • 1k
  • 3
  • 13
  • 34

How do I set the front page programmatically?

I need to allow my users to set the default page of the blog. So when someone visits, "www.example.com/blog/" the page they see is either the blog posts list or a specific page.

It looks like I can tell which page is already set using:

get_option( 'page_on_front' ): returns the ID of the static page assigned to the front page. 

source

Can I change that by using:

set_option( 'page_on_front', 10 );

How would I remove a specific front page that has already been set? Do I set it to null?

UPDATE:

I found this call to check if showing blog posts:

get_option( 'show_on_front' ) == 'posts';

source

1.21 gigawatts
  • 1k
  • 3
  • 13
  • 34