Today we needed to get the permalink of a page in WordPress whose post_type is “page”. To do this, we had to
combine two functions, which are: get_permalink() and get_page_by_path().
How to Get a Page Permalink using the Page Name:
| |
How to Get a Page Permalink using the Page Slug:
| |
Note About Page Hierarchy and Slugs.
If you have a page hierarchy, you’ll have to pass the complete slug, including the parent page, to the
get_page_by_path() function.
For example: to get the permalink of a child page called “Festas” with a parent page called “Eventos”, we would do this:
| |
You can check the functions mentioned above directly in the official WordPress documentation.
That was a very short post, if you have questions, leave a comment!