Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get page link


Retrieves the permalink for the current page (if in The Loop) or any arbitrary page ID if passed as the first argument. All arguments are optional. All arguments default to false.

If $id is passed, it will be the id of the page whose link is returned.

$leavename can be used to toggle off the switching out of "%pagename%" in permalinks.

$sample returns a sample permalink.


<?php get_page_link($id$leavename$sample); ?>


(mixed) (optional) Page ID
Default: false
(bool) (optional) Whether to keep page name
Default: false
(bool) (optional) Is it a sample permalink?
Default: false

Return Value

A string containing the permalink.


This example will display a link named "Map", to page with id number 40.

<a href="<?php echo get_page_link(40); ?>">Map</a>


Page Tags: get_all_page_ids(), get_ancestors(), get_page(), get_page_link(), get_page_by_path(), get_page_by_title(), get_page_children(), get_page_hierarchy(), get_page_uri(), get_pages(), is_page(), page_uri_index(), wp_list_pages(), wp_page_menu()

See also index of Function Reference and index of Template Tags.