checkURL
- 2010 Feb 24
- Comments 0
- Published In PHP, Snippets
I often run into a problem with Wordpress with telling what page I am on or what parent I am on. I was attempting to use is_page(), but often ran into a problem when I wanted to determine what parent or grandparent page I was on. This function allows us to look at the URL and dissect it. Then we can determine if the slug we are looking for is in the correct location. If it is there, then the function returns true, if it isn’t it does nothing. The function splits the URL of the full page by the forward-slash. This starts after the .com/. So, to know where you want to find your slug, you just count that many space over.
Snippet
$currentPage = explode('/', $_SERVER['REQUEST_URI']);
if($currentPage[$position] == $uri):
return true;
endif;
}
Use
- Add to your functions.php file in your theme. In your theme file create an if loop
- Insert in your if loop
checkURL('uri-you-want-to-find', position in full URL) - Replace ‘uri-you-want-to-find’ in to the slug you want to find in single quotes
- Replace ‘position in full URL’ to a number, that represents the space in your url as discussed above
- Loop away!




















