[wp-trac] [WordPress Trac] #63044: Add method to test whether currently viewing the site home page in WP_Query
WordPress Trac
noreply at wordpress.org
Mon Mar 3 16:56:38 UTC 2025
#63044: Add method to test whether currently viewing the site home page in WP_Query
-------------------------+-----------------------------
Reporter: joedolson | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Query | Version:
Severity: normal | Keywords: needs-patch
Focuses: |
-------------------------+-----------------------------
Currently, WP_Query offers to methods to test the home page qualities for
a site, `is_front_page()` and `is_home()`, but neither of these actually
verify that this is truly the site's home page.
To test the home page, you need to check both values, compare them against
the queried object ID, and verify that pagination isn't set.
While this isn't particularly complex (`$is_front = ! is_paged() && (
is_front_page() || ( is_home() && ( (int) get_option( 'page_for_posts' )
!== get_queried_object_id() ) ) );`), it is confusing and verbose.
Adding a method such as `is_home_page()` that produced this logic would
make it simpler to test whether you are viewing the actual root.
See #62895 as a case where this would have been helpful for
simplification.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/63044>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list