From the get Get_Pages documentation (https://codex.wordpress.org/Function_Reference/get_pages) I understand it should look more or less like this:

<?php $args = array(
    'post_type' => 'page',
    'post_status' => 'publish'
$pages = get_pages($args); 

But where do I specify that it's the homepage I'd like to get?

1 Answer 1


That depends on what your trying to do.

If you want to get the page content in another template or functions file and your home page is a page that you created in the dashboard and set as the static front page you can use get_page_by_path function like this:

get_page_by_path('the_path_of_the_page'); // Usually will be 'home'

Or if you want to use get_pages you can do the following:

<?php $args = array(
    'post_type' => 'page',
    'post_status' => 'publish',
    'post_name' => 'the_slug_of_the_page' // This also will likely be 'home' for the home page'
$home = get_pages($args); 

See get_page_by_path in the Codex.

  • Thanks. It doesn't seem the path of the homepage is "home". How can I find it?
    – Ben Carp
    Commented Aug 2, 2017 at 13:38
  • If you have a static page, in your admin dashboard in the pages menu, search for a page with a - Front Page in the front of the name. e.g Home - Front Page. If you don't see any, that means that you have a static file, this cold be a file called home.php or front-page.php. Go to your theme directory and see if you find it there. Commented Aug 2, 2017 at 13:44
  • Thanks. So in the get_page_by_path, the path is actually the path of the template/php file. Right? As for the get_pages option, I don't understand what you mean by 'the_slug_of_the_page' when referring to the homepage. My understanding is that the slug is what appears after the base URL, which in case of the homepage is empty.
    – Ben Carp
    Commented Aug 2, 2017 at 14:17
  • No, the path in this case is technically the slug of the page. But when using child pages e.g mysite.com/page/child-page, the path is page/child-page (this isn't relevant in your case, but is good to know). Yes the slug is what appears after the name of the page, and when you set a static page, it doesn't appear in the url, but the page still have it. Commented Aug 2, 2017 at 14:24

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.