7

Get Page URL from Slug in WordPress

 3 years ago
source link: https://pineco.de/snippets/get-page-url-from-slug-in-wordpress/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Get Page URL from Slug in WordPress

We use cookies for commenting and analytics. For more details, please visit our privacy page.

Ugrás a tartalomhoz

In WordPress to get any URL, we can use the get_permalink() function using a post ID or a post object.

One cool feature is to get a page link using its slug or title using other helper functions. Identify an URL by its slug is useful if you don’t know the correct ID; this can happen in a lot of cases like if your development environment differs from the live one.

The two needed helper , in this case, are get_page_by_path() and get_page_by_title(). Both functions came back with a post object, the first using the slug while the second using the title.

get_permalink( get_page_by_path( 'contact' ) );
get_permalink( get_page_by_title( 'Contact' ) );

Reference – Get Page Link from Slug


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK