WordPress.org

Make WordPress Core

Opened 11 months ago

Closed 8 months ago

Last modified 8 months 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:

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 (5)

comment:1 SergeyBiryukov10 months ago

  • Component changed from Rewrite Rules to Query

Basically, you're adding a custom query variable:

http://mysite.com/?questions_category=...

WP_Query still considers this a home page, since it's the default fallback if none of the other conditions are true. See the comments on #18114.

Version 0, edited 10 months ago by SergeyBiryukov (next)

comment:2 wonderboymusic8 months 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

comment:3 LucasMS8 months 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.

comment:4 markoheijnen8 months ago

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

comment:5 SergeyBiryukov8 months ago

  • Resolution changed from wontfix to duplicate

Duplicate of #18114.

Note: See TracTickets for help on using tickets.