GavinJaynes
6/19/2014 - 9:35 AM

Wordpress has built in conditional functions such as is_page() and is_front(), but sometimes it's not enough. This function checks if the cu

Wordpress has built in conditional functions such as is_page() and is_front(), but sometimes it's not enough. This function checks if the current url contains a slug and returns true or false respectively.

/**
 * This function checks if the page you're on is a certain page 
 * @param $slug the slug of the page you are checking for
*/
function is_this_page($slug) {

  	$current_url = home_url(add_query_arg(array()));
  
  	if (false !== strpos($current_url, $slug)) {

    	return true;

  	} else {

    	return false;
  	}
}