#24473 closed enhancement (duplicate)
is_home returns true for pages created with custom rewrite_rules
Reported by: | LucasMS | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.5.1 |
Component: | Query | Keywords: | |
Focuses: | Cc: |
Description
I have a plugin for question and answers, where the questions index and question pages are created using add_rewrte_rule . (I know I could do something similar using custom post types, but this plugin was done long before this feature).
here are my rewrites called in init hook:
add_rewrite_rule('^questions/([^/]+)/?', 'index.php?questions_category=$matches[1]', 'top'); add_rewrite_tag('%questions_category%', '([^&]+)');
The problem is, in the header of the template I use is_home() to load some custom codes, but is_home() is returning true in theses question pages.
Tthese pages are not of any wordpress type (post, page, 404, home, archives - tax, dates, categories and so on). My suggestion is to create a new is_dynamic boolean variable for this kind of pages.
Change History (6)
#2
@
11 years ago
- Milestone Awaiting Review deleted
- Resolution set to wontfix
- Status changed from new to closed
Filter query_vars
, add questions_category
to it, and then use get_query_var( 'questions_category' )
in your theme to know when you're on it
#3
@
11 years ago
wonderboymusic, that was not the problem. I know what you said, but, I have some codes in the header that should only be loaded in the home page, and I used is_home() for that. But is_home returns true when it's not the home. For me, this is a problem.
Basically, you're adding a custom query variable:
WP_Query still considers this a home page, since
is_home
the default fallback if none of the other conditions are true. See the comments on #18114.