10

I'm building a Wordpress plugin in which I need to get the HOME page ID value.

Do you know how can I get it?

I know that we can get the current ID with the_ID() or get_the_ID() function, but I need specificly the HOME page ID value.

My plugin is located at the following directory path:

wp-content/plugins/myPlugin/
3
  • Are you using front-page.php or you created a specific page just to be the home page of your website? If you used front-page.php (or index.php), then you don't have any ID associated with it. Sep 18, 2015 at 18:37
  • The homepage do not have an ID Sep 18, 2015 at 18:41
  • Can you elaborate on your roadblock requiring the homepage ID? I can't seem to imagine a scenario where using is_front_page() and writing a slightly longer function wouldn't solve every problem.
    – deflime
    Sep 18, 2015 at 19:07

2 Answers 2

32

$pageID = get_option('page_on_front'); should get you the Page ID of the page set as 'Front Page' (Homepage) in WordPress options.

$pageID = get_option('page_for_posts'); should get you the Page ID of the page set as 'Posts Page' in WordPress options.

In any case, if the returned value is 0, that means no static page is set for that option.

1
  • 1
    Home page is the posts page - this is the option for the Front page, which might colloquially be known as the home page, but in WordPress means something different. Jun 20, 2017 at 9:05
7

If by Home Page you mean the page designated as the Posts page, the ID is stored in the option page_for_posts. If the value is 0, there is no designated home page.

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.