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;
    }
}
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

Comments

You can leave a response, or trackback from your own site.

Before you add comment see for rules.

Leave a Reply

Your email address will not be published. Required fields are marked *

5u2g0d