Example 1 — Get the URL of one page
Pass the ID of the page.
<?php
echo esc_url( get_page_link( 15 ) ); How It Works
15is the ID of the About page.get_page_link()returns its address.esc_url()keeps the output safe.

In WordPress, get_page_link() returns the URL of a page. Pass a page ID, and you get its address back as a string.
It is made for pages. For posts, use get_permalink(), which works for pages as well. If you do not pass an ID, the function uses the current page.
Pass a page ID and print the result with esc_url().
<?php echo esc_url( get_page_link( 15 ) ); ?> | Call | What it does |
|---|---|
get_page_link( 15 ) | The URL of the page with ID 15. |
get_page_link() | The URL of the current page. |
get_page_link( 15, true ) | Keep the page name as a placeholder. |
It returns the URL. It does not print anything.
get_page_link( int|WP_Post $post = false, bool $leavename = false, bool $sample = false ): string | Parameter | Description |
|---|---|
$post | int|WP_Post|false. Page ID or object. Default is false, which means the current page. |
$leavename | bool. If true, the page name stays as a placeholder (%pagename%). Default is false. |
$sample | bool. If true, build a sample link for pages that are not published yet. Default is false. |
| Return Value | Description |
|---|---|
| string | The page URL. |
Three short examples. Each one shows the code and what it prints or does.
Pass the ID of the page.
<?php
echo esc_url( get_page_link( 15 ) ); 15 is the ID of the About page.get_page_link() returns its address.esc_url() keeps the output safe.Loop over your pages and link to each one.
<?php
$pages = get_pages();
echo '<ul>';
foreach ( $pages as $page ) {
echo '<li><a href="' . esc_url( get_page_link( $page->ID ) ) . '">' . esc_html( $page->post_title ) . '</a></li>';
}
echo '</ul>'; get_pages() returns all published pages.get_page_link() builds the link of each page.esc_html() escapes the page title.The leavename option is useful in tools that edit the permalink.
<?php
echo esc_url( get_page_link( 15, true ) ); $leavename.true, the real name is replaced by %pagename%.false is normal.Return the permalink of a post, page, or other post type.
18 people found this page helpful