Alternative to WordPress is_home()

Do you have a static page set for your homepage and a blog posts section set as well? I bet you’ve tried the built in WordPress function is_home() that will return true for both the homepage and the blog section and have gotten frustrated.

Have no fear! I have created a function that I use on a continuous basis to check if the current page is the homepage.

Add this to your functions.php file in your theme folder:

function is_it_home($post_id=0) {
	global $post;
	$post_id=$post->ID;
	$frontpage=get_option('page_on_front');
	
	if ($post_id == $frontpage) {
		return true;
	}else{
		return false;
	}
	
}




One Response to “Alternative to WordPress is_home()”

  1. Great! :)


    August 31, 2009 at 1:27 am

Leave a Reply