Wordpress 2.3 is_home fix
by Sapphire (September 27, 2007)
Note: found the fix.
I’ve updated to Wordpress 2.3 and discovered “is_home” doesn’t work - and not just if you use a static page as your first page. Somehow, Wordpress seems to be interpreting every “page” as the home page. My home-only stuff is showing up on Page 2, 3, etc. as well as all my static pages.
Normally, to have something display only on the homepage - like my text link ads in the sidebar, you just put that something in between these two lines of code:
<?php if ( is_home() ) : ?>
<?php endif // is_home() ?>
I thought I’d found a fix with the Is_Frontpage plugin from Bos89 but it caused the stuff to stop showing on the front page as well. It’s like Wordpress can’t distinguish the front page of blog entries from other pages.
Anyone found a fix?


October 1st, 2007 at 3:31 pm
I haven’t upgraded to 2.3 yet (still waiting to see if all my plugins are supported) but I do make use of this “is_home” function as well.
Maybe you could use “$_SERVER['REQUEST_URI'];” and only show your is_home content if it equals “/” or “/index.php”
That should work
October 1st, 2007 at 3:43 pm
Derek, I’m such a noob on programming I have no idea where to stick that bit of code (theme file? htaccess?). If you can break it down into instructions for the feeble minded without giving yourself a headache, that would be much appreciated.
October 2nd, 2007 at 9:37 pm
Sorry
Well, “is_home()” returns “true” if you are on the home page.
“$_SERVER[’REQUEST_URI’]” returns the “visible” url (not the script file) minus your domain name. Examples are “/”, “/index.php”, “/wordpress-23-is_home-fix/”, etc
So, to get the same result, you would change:
<?php if (is_home()) : ?>
to:
<?php if ($_SERVER[’REQUEST_URI’] == ‘/’ || $_SERVER[’REQUEST_URI’] == ‘/index.php’) : ?>
You could even make a new function (and put it in a WordPress functions file) like this:
<?php
function is_home_uri() {
if ($_SERVER[’REQUEST_URI’] == ‘/’ || $_SERVER[’REQUEST_URI’] == ‘/index.php’) { return true; }
else { return false; }
}
?>
and then just substitute “is_home()” with “is_home_uri()”
** I haven’t tested this code so I’m not sure that it works 100%, but it should
October 2nd, 2007 at 10:35 pm
Well, I tried your first version only, because I’m not sure how to make a functions file. It didn’t seem to work, either. And it returned a “division by zero” error.
Of course, it’s VERY possible I was doing something wrong. But your instructions seemed pretty straightforward. Hmm.
Thanks for the info!
October 7th, 2007 at 11:31 pm
When you paste in the code, change the quotes into regular single quotes (next to the enter key). That should fix the divide by zero problem.
October 10th, 2007 at 1:07 pm
What Todd said works! Thanks Todd!
December 12th, 2007 at 11:54 am
I used this code to differentiate some display in my sidebar. Runs perfect if regular single quotes are used. Thanks, I spent a lot of time to deal with this problem.
March 26th, 2008 at 1:19 pm
I wrote this function:
function is_homepage() {
$siteurl = get_option(’home’);
if($siteurl[strlen($link)-1] != “/”) {
$siteurl .= “/”;
}
$self_url = sprintf(’http%s://%s%s’,
(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == TRUE ? ’s’: ”),
$_SERVER['HTTP_HOST'],
$_SERVER['REQUEST_URI']
);
if ($siteurl == $self_url) return true;
else return false;
}