Skip to content

Instantly share code, notes, and snippets.

@GavinJaynes
Created June 19, 2014 09:35
Show Gist options
  • Save GavinJaynes/a806e7be09e11c7957ec to your computer and use it in GitHub Desktop.
Save GavinJaynes/a806e7be09e11c7957ec to your computer and use it in GitHub Desktop.
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment