Title: _get_page_link
Published: April 25, 2014
Last modified: August 20, 2026

---

# _get_page_link( int|WP_Post $post, bool $leavename = false, bool $sample = false ): string

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/_get_page_link/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/_get_page_link/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/_get_page_link/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/_get_page_link/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/_get_page_link/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/_get_page_link/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/_get_page_link/?output_format=md#changelog)

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Retrieves the page permalink.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/_get_page_link/?output_format=md#description)󠁿

Ignores page_on_front. Internal use only.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/_get_page_link/?output_format=md#parameters)󠁿

 `$post`int|[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)
optional

Post ID or object. Default uses the global `$post`.

`$leavename`booloptional

Whether to keep the page name.

Default:`false`

`$sample`booloptional

Whether it should be treated as a sample permalink.

Default:`false`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/_get_page_link/?output_format=md#return)󠁿

 string The page permalink.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/_get_page_link/?output_format=md#source)󠁿

    ```php
    function _get_page_link( $post = 0, $leavename = false, $sample = false ) {
    	global $wp_rewrite;

    	$post = get_post( $post );

    	$force_plain_link = wp_force_plain_post_permalink( $post );

    	$link = $wp_rewrite->get_page_permastruct();

    	if ( ! empty( $link ) && ( ( isset( $post->post_status ) && ! $force_plain_link ) || $sample ) ) {
    		if ( ! $leavename ) {
    			$link = str_replace( '%pagename%', get_page_uri( $post ), $link );
    		}

    		$link = home_url( $link );
    		$link = user_trailingslashit( $link, 'page' );
    	} else {
    		$link = home_url( '?page_id=' . $post->ID );
    	}

    	/**
    	 * Filters the permalink for a non-page_on_front page.
    	 *
    	 * @since 2.1.0
    	 *
    	 * @param string $link    The page's permalink.
    	 * @param int    $post_id The ID of the page.
    	 */
    	return apply_filters( '_get_page_link', $link, $post->ID );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/link-template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/link-template.php#L428)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/link-template.php#L428-L457)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/_get_page_link/?output_format=md#hooks)󠁿

 [apply_filters( ‘_get_page_link’, string $link, int $post_id )](https://developer.wordpress.org/reference/hooks/_get_page_link/)

Filters the permalink for a non-page_on_front page.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/_get_page_link/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_force_plain_post_permalink()](https://developer.wordpress.org/reference/functions/wp_force_plain_post_permalink/)`wp-includes/link-template.php` |

Determine whether post should always use a plain permalink structure.

  | 
| [user_trailingslashit()](https://developer.wordpress.org/reference/functions/user_trailingslashit/)`wp-includes/link-template.php` |

Retrieves a trailing-slashed string if the site is set for adding trailing slashes.

  | 
| [get_page_uri()](https://developer.wordpress.org/reference/functions/get_page_uri/)`wp-includes/post.php` |

Builds the URI path for a page.

  | 
| [WP_Rewrite::get_page_permastruct()](https://developer.wordpress.org/reference/classes/wp_rewrite/get_page_permastruct/)`wp-includes/class-wp-rewrite.php` |

Retrieves the page permalink structure.

  | 
| [home_url()](https://developer.wordpress.org/reference/functions/home_url/)`wp-includes/link-template.php` |

Retrieves the URL for the current site where the front end is accessible.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [get_post()](https://developer.wordpress.org/reference/functions/get_post/)`wp-includes/post.php` |

Retrieves post data given a post ID or post object.

  |

[Show 3 more](https://developer.wordpress.org/reference/functions/_get_page_link/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/_get_page_link/?output_format=md#)

| Used by | Description | 
| [get_post_comments_feed_link()](https://developer.wordpress.org/reference/functions/get_post_comments_feed_link/)`wp-includes/link-template.php` |

Retrieves the permalink for the post comments feed.

  | 
| [get_page_link()](https://developer.wordpress.org/reference/functions/get_page_link/)`wp-includes/link-template.php` |

Retrieves the permalink for the current page or page ID.

  | 
| [get_attachment_link()](https://developer.wordpress.org/reference/functions/get_attachment_link/)`wp-includes/link-template.php` |

Retrieves the permalink for an attachment.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/_get_page_link/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.1.0](https://developer.wordpress.org/reference/since/2.1.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2F_get_page_link%2F)
before being able to contribute a note or feedback.