How to check if a page exists by url?

There may be a situation when you need to display content based on existence of a page or non-hierarchical custom post by url. As the example below there are two different parent pages for the same page slug. We assume that certain pages will have the same title, and just have different parent pages. So we want to check if a page exists by url?

check if a page exists by url

For the existence for a page, we can make a list of paths of paths to check

The get_page_by_path() function is quite handy in such case which retrieves a page given its path. You can also check if a custom post of non-hierarchical custom post types exists by url through providing third parameter to this function in the same manner.

Like this Post? Share