Opened 2 years ago
Last modified 2 years ago
#16802 new enhancement
is_page() doesn't accept a full path
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Query | Version: | 3.1 |
| Severity: | minor | Keywords: | 2nd-opinion has-patch |
| Cc: | johnbillion@… |
Description
If you have a page at example.com/foo/bar, then is_page('foo/bar') will return false on that page.
The is_page() function only checks the ID, title and post name, not the full path.
If the $page parameter passed to is_page() contains a slash then we should check the full path. If I get a chance I'll see if I can whip up a patch in the next couple of days.
Attachments (1)
Change History (7)
comment:1
johnbillion — 2 years ago
- Cc johnbillion@… added
comment:3
in reply to:
↑ 2
johnbillion — 2 years ago
Replying to hakre:
I suggest to name such a function is_page_path('foo/bar') for a starter to prevent further parameter overloading of is_page().
What's "parameter overloading"? Why do we need another function?
- Keywords 2nd-opinion added
is_page() accepts slug and title, I don't think there is need for is_page( path ) or is_page_path function.
function is_page_path( $path ) {
$page = get_page_by_path( $path );
return $page ? is_page( $page->ID ) : null;
}
Something like that?
-1 to having this in core, it seems like a niche and untidy way of doing things.
johnbillion — 2 years ago
comment:6
johnbillion — 2 years ago
- Keywords has-patch added
Patch.
@hakre, @greuben and @kawauso: Why the opposition? is_page() accepts a slug, so accepting a full path is a natural extension. In fact it's not even a natural extension, I'd say it's expected behaviour. Multiple pages with different parents can have the same slug, so this eliminates the ambiguity.

I suggest to name such a function is_page_path('foo/bar') for a starter to prevent further parameter overloading of is_page().