WordPress get_page_link() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Returns a URL

Definition

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.

Syntax

Pass a page ID and print the result with esc_url().

WordPress
<?php echo esc_url( get_page_link( 15 ) ); ?>
CallWhat 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.

Full declaration
WordPress
get_page_link( int|WP_Post $post = false, bool $leavename = false, bool $sample = false ): string

Parameters

ParameterDescription
$postint|WP_Post|false. Page ID or object. Default is false, which means the current page.
$leavenamebool. If true, the page name stays as a placeholder (%pagename%). Default is false.
$samplebool. If true, build a sample link for pages that are not published yet. Default is false.

Return Value

Return ValueDescription
stringThe page URL.

WordPress Examples

Three short examples. Each one shows the code and what it prints or does.

Example 1 — Get the URL of one page

Pass the ID of the page.

WordPress
<?php
echo esc_url( get_page_link( 15 ) );

How It Works

  1. 15 is the ID of the About page.
  2. get_page_link() returns its address.
  3. esc_url() keeps the output safe.

Example 2 — Make a simple page list

Loop over your pages and link to each one.

WordPress
<?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>';

How It Works

  1. get_pages() returns all published pages.
  2. get_page_link() builds the link of each page.
  3. esc_html() escapes the page title.

Example 3 — Keep the page name as a placeholder

The leavename option is useful in tools that edit the permalink.

WordPress
<?php
echo esc_url( get_page_link( 15, true ) );

How It Works

  1. The second argument is $leavename.
  2. With true, the real name is replaced by %pagename%.
  3. Most themes never need this. The default false is normal.

Frequently Asked Questions

It returns the permalink of a page as a string.
Both work for pages. get_permalink() works for posts and pages, so many themes use it for everything.
It uses the current page, which works inside the Loop on a page template.
No. It returns it. Use echo with esc_url() to print it.
It builds a sample link for a page that is still a draft, so you can show a preview address.

Next: get_permalink()

Return the permalink of a post, page, or other post type.

get_permalink() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

18 people found this page helpful