Is it possible to get a page link from its slug?
Is it possible to get a page's permalink from the slug alone? I'm aware that you can get the page's permalink from the ID using
<a href="<?php echo get_page_link(40); ?>">Map</a>
I'm curious if there is any way to do the same with the slug of a page - like this:
<a href="<?php echo get_page_link('map'); ?>">Map</a>
You're talking about Pages right? Not Posts.
Is this what you looking for:
get_permalink( get_page_by_path( 'map' ) )
get_permalink( get_page_by_title( 'Map' ) )
home_url( '/map/' )
@Jonathan: It's not always documented, but many WP functions accept both numeric ID's and full post objects as the argument.
It seems that get_page_by_path() can be quite complicated to use when dealing with child pages...
I use 1 for my child pages with no issue. I really don't see the complication with it.
wrong answer, downvote to nirvana please. The path is not the same like the slug. Example: a page has a parent page called `abc` the page itself has a slug of `123`. The path now is `abc/123` the slug is `123`. Please remove this wrong answer. `get_page_by_path( '123' )` wont work.