Retrieve The Permalink For a Page and Post Type

Do you know that the WordPress have some useful functions to link page and archive page? Let’s see them in action.

Scenario :
You would normally grab a page link via its ID but in the case that you had a localhost which install and an online install the ID was different, how you can link the page?

Get the permalink for a page by name

Get the permalink for a page by title

Get the permalink for a page by slug

Get the permalink for a page by parent/child

Scenario :
If you want to get the permalink using the method with child-page, then you need to pass the full slug. So, in this case we have a child page “about” with a parent pages which called “skills”.

Get the link to custom post type archive page

Scenario :
If you have a custom posts loop and in the bottom you want to add “View all” link, then how you should lead to the page with all posts that type?

Note:
In case that get_post_type_archive_link() returns false, make sure that you have used the argument has_archive => true when using register_post_type().


Also you can read


Leave a Reply

Your email address will not be published. Required fields are marked *