On this page
get_page_link( int|WP_Post $post = false, bool $leavename = false, bool $sample = false ): string
Retrieves the permalink for the current page or page ID.
Description
Respects page_on_front. Use this one.
Parameters
$postint|WP_Post Optional-
Post ID or object. Default uses the global
$post.Default:
false $leavenamebool Optional-
Whether to keep the page name.
Default:
false $samplebool Optional-
Whether it should be treated as a sample permalink.
Default:
false
Return
string The page permalink.
Source
File: wp-includes/link-template.php. View all references
function get_page_link( $post = false, $leavename = false, $sample = false ) {
$post = get_post( $post );
if ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $post->ID ) {
$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 );
}
Hooks
- apply_filters( 'page_link',
string $link ,int $post_id ,bool $sample ) -
Filters the permalink for a page.
Related
Uses
| Uses | Description |
|---|---|
| _get_page_link() wp-includes/link-template.php | Retrieves the page permalink. |
| home_url() wp-includes/link-template.php | Retrieves the URL for the current site where the front end is accessible. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
| get_option() wp-includes/option.php | Retrieves an option value based on an option name. |
| get_post() wp-includes/post.php | Retrieves post data given a post ID or post object. |
Used By
| Used By | Description |
|---|---|
| get_permalink() wp-includes/link-template.php | Retrieves the full permalink for the current post or post ID. |
Changelog
| Version | Description |
|---|---|
| 1.5.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_page_link