3

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

BTW This is on a network site (Wordpress MU).

6
  • Logically, you could do it but it is not a good approach, just define a constant of that page id. And it reduce query loading time!
    – Por
    Commented Oct 19, 2015 at 1:11
  • You want registered users to set the default page when they visit the site and are logged in? Commented Oct 19, 2015 at 5:09
  • Sort of. I want to do it through a UI I have Commented Oct 19, 2015 at 5:15
  • @1.21gigawatts - if you want this to be per-user, then the solution I gave is not correct and you're going about this wrong. that's a global setting for all visitors.
    – Milo
    Commented Oct 19, 2015 at 16:16
  • When a user logs into their site they can go to their reading page and set the default home page for their site. I want my application to be able do that as well. I'm doing this on a network site (Wordpress MU). Commented Oct 19, 2015 at 20:21

1 Answer 1

3

If you manually enter the admin URL wp-admin/options.php you'll see a list of all options and their values.

show_on_front is page when a page is selected to show on front. page_on_front and page_for_posts are 0 when no pages are chosen.

You can use update_option to change these values, there is no set_option function.

5
  • Can I use one of these properties to hold a value? If I set page_for_posts to a value will that change anything or do I need to set show_on_front to "page" as well? I want to set the pageforposts to a value I can reference later. Commented Oct 26, 2015 at 5:23
  • 1
    If you're doing something non-standard, just save the value in your own option.
    – Milo
    Commented Oct 26, 2015 at 15:22
  • The answer is to store a custom option per blog with update_blog_option(blog_id, "project_site_option", value); FYI API parameters may not be in correct order. Commented Nov 12, 2015 at 5:34
  • you're using multisite? your question says nothing about multisite.
    – Milo
    Commented Nov 12, 2015 at 15:19
  • Yeah sorry. I mentioned it in the comments but not the original post. I'll update it. BTW I was agreeing with your comment, "If you're doing something nonstandard save your own option". Commented Nov 12, 2015 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.