Strange Behaviour with is_home()

I’m having an odd issue, although I can understand why it works like this I do need to find a way around it.

I have used the the request filter to modify the query for the home/index page to select for a post type other than ‘post’

The result of this is that is_home() is returning false in the index.php template. If I disable the filter then is_home() goes back to returning true.

Anyway to force the is_home() to return true? or another way to approach this?

Thanks, Stewart.

Solutions Collecting From Web of "Strange Behaviour with is_home()"

From look at the code the following logic happens in your case:

  • query is for one post type that has archive
  • is_post_type_archive gets set to true
  • is_archive gets set to true
  • is_home gets set to false since it is seen as archive

I am not sure about all implications without extensive testing, but probably approaches are either:

  1. artificially set is_home to true under those circumstances
  2. ignore failing is_home() and use different conditional