get_page_link( int|WP_Post $post = false, bool $leavename = false, bool $sample = false )
Retrieves the permalink for the current page or page ID.
Description Description
Respects page_on_front. Use this one.
Parameters Parameters
- $post
-
(int|WP_Post) (Optional) Post ID or object. Default uses the global
$post.Default value: false
- $leavename
-
(bool) (Optional) Whether to keep the page name.
Default value: false
- $sample
-
(bool) (Optional) Whether it should be treated as a sample permalink.
Default value: false
Return Return
(string) The page permalink.
Source Source
File: wp-includes/link-template.php
function get_page_link( $post = false, $leavename = false, $sample = false ) {
$post = get_post( $post );
if ( 'page' == get_option( 'show_on_front' ) && $post->ID == get_option( 'page_on_front' ) ) {
$link = home_url( '/' );
} else {
$link = _get_page_link( $post, $leavename, $sample );
}
/**
* Filters the permalink for a page.
*
* @since 1.5.0
*
* @param string $link The page's permalink.
* @param int $post_id The ID of the page.
* @param bool $sample Is it a sample permalink.
*/
return apply_filters( 'page_link', $link, $post->ID, $sample );
}
Expand full source code Collapse full source code View on Trac
Changelog Changelog
| Version | Description |
|---|---|
| 1.5.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
<a href="<?php echo esc_url( get_page_link( 40 ) ); ?>"> <?php esc_html_e( 'Map', 'textdomain' ); ?> </a>