We used to write custom functions to return these values until we discovered you can pass get_permalink a function that will return the ID.
Examples..
Get Permalink By Page Name
<a href="<?php echo get_permalink( get_page_by_path( 'Events' ) ) ?>">Events</a>
Get Permalink By Page Slug
<a href="<?php echo get_permalink( get_page_by_path( 'events' ) ) ?>">Events</a>
Note On Hierarchical Pages and The Slug
If you have a page hierarchy you will have to pass the full slug including the parent to the get_page_by_path function.
Example… To get the permalink using method with child page, you need to pass the full slug. In this case we have a child page called “Parties” with a parent page called “Events”.
<a href="<?php echo get_permalink( get_page_by_path( 'events/parties' ) ) ?>">Parties</a>
Category : Blog &wordpress development



