What are the different ways to detect wordpress homepage
except is_front_page()
and is_home()
Thanks
What are the different ways to detect wordpress homepage
except is_front_page()
and is_home()
Thanks
You must be logged in to post a comment.
is_front_page()
is what you want.I assume, by the fact that
is_home()
is not working, that your home page is static, according to the settings in wp-admin.is_home()
returns true on your main blog page whereasis_front_page()
returns true on which ever page is defined as your front page, feed or not.From codex:
I just do the following:
It works and doesn’t overcomplicate things, especially as
is_front_page()
andis_home()
don’t always work as you’d expect them to.With Twenty Ten I use:
Works like a charm… $_SERVER is the one I always use and it always works.
from outside the loop:
In many situations a WordPress site can have is_home and is_frontpage both eval as true on the REAL homepage and also on the main blog page. After building sites in WordPress for about 4 years this still bothers me.
For example if you have a site where you have your latest posts on your homepage with maybe a slider or some other homepage-centric elements, AND have another blog page, then is_frontpage and is_home will both eval as true on BOTH pages. So WordPress does not have a clear conditional function for the true homepage, at least the way most people think of the homepage of a website.
So I agree with Liam that if you get into a confusing situation, something like
if ( $_SERVER[“REQUEST_URI”] == ‘/’ ) { }
is more reliable.
For me
is_front_page()
andis_home()
doesn’t work in ways I need to check the homepage, so instead I write this condition:To me, all previous answers, some are clearly sometime wrong, and some not working always because it depend where (stack) you need to know if you are or not into WP homepage.
I did not found any valid answer here, nor elsewhere, so i’ll do this instead that will work always, except in rare situations where the query string is appended into home url for some reason. In this (very rare) case, the code should be then little improved, but generally, this will work where others will fails:
Ok with any permalink.
[EDITED]
Do not change the global $_SERVER[‘REQUEST_URI’] value
is_home()
is the way to go.Have you tried this method and it doesn’t work? If yes, it has usually something to do with the mod_rewrite settings or the wordpress settings itself.