Make WordPress Core

Opened 9 years ago

Closed 8 years ago

Last modified 4 years ago

#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:


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)

#1 @SergeyBiryukov
8 years ago

  • Component changed from Rewrite Rules to Query

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.

Last edited 8 years ago by SergeyBiryukov (previous) (diff)

#2 @wonderboymusic
8 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 @LucasMS
8 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.

#4 @markoheijnen
8 years ago

You can still set is_home to false on the action 'pre_get_posts'. That is what I do.

#5 @SergeyBiryukov
8 years ago

  • Resolution changed from wontfix to duplicate

Duplicate of #18114.

#6 @mordauk
7 years ago

Looks like the patch on #25143 likely resolves this too.

Last edited 4 years ago by SergeyBiryukov (previous) (diff)
Note: See TracTickets for help on using tickets.