Opened 5 months ago
Last modified 5 months ago
#63044 new enhancement
Add method to test whether currently viewing the site home page in WP_Query
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Query | Keywords: | has-patch |
Focuses: | Cc: |
Description
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.
Change History (1)
This ticket was mentioned in PR #8442 on WordPress/wordpress-develop by @abcd95.
5 months ago
#1
- Keywords has-patch added; needs-patch removed