Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get ID of front page Wordpress

Tags:

wordpress

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

like image 378
pbond Avatar asked Jan 03 '13 22:01

pbond


3 Answers

The ID of the page used as static page is stored in the wp_options WP table, as option_name=page_on_front and option_value=ID of the page. So if you want to retrieve this value, just use get_option('page_on_front').

like image 101
barakadam Avatar answered Oct 12 '22 07:10

barakadam


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:

$pageID = get_option('page_for_posts'); 

does the trick for that situation.

like image 3
Bram Avatar answered Oct 12 '22 05:10

Bram


Here is an idea:

Get the page by Title first

$Page = get_page_by_title( 'test' );

Then, get the ID like this

echo $Page->ID . "<br /><br />";
like image 1
Felipe Alameda A Avatar answered Oct 12 '22 05:10

Felipe Alameda A