Sometimes we want to check if the user is on home page. This can be done by this little function. Just add this code to your functions.php
and use it likt this:
if (is_homepage()){ return true; }
Source:
function is_homepage(){
$siteurl = get_option('home');
if ($siteurl [strlen ( $siteurl ) - 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;
}
}
Leave a Reply