In the WordPress admin settings>reading you can configure the ‘frontpage displays as’ as being a static page for the front page. Now I would like to retrieve the ID of the selected static page which is set to display as front page. I’ve tried Googling but to not much avail, thus I was wondering if there is a native function to retrieve this ID. (I don’t feel like programming a workaround if there is a native direct function for this).
Leave a Reply
You must be logged in to post a comment.
The ID of the page used as static page is stored in the
wp_options
WP table, asoption_name
=page_on_front
andoption_value
=ID of the page.So if you want to retrieve this value, just use
get_option('page_on_front')
.I was looking for the solution where you select a page as placeholder for the blog archive.
You can do the same, but then query for ‘page_for_posts’ instead of ‘page_on_front’. So:
does the trick for that situation.
Here is an idea:
Get the page by Title first
Then, get the ID like this
The easiest way to see the page_id of the static page is to change the static page to another page and then go to Pages and click on the old page. The page_id is displayed in the Permalink above the edit area. After you see the page_id you can change the static page to the old one. The Permalink for the static page does not show the page_id but for all other pages it does.