_get_page_link()
Retrieves the page permalink.
Ignores page_on_front. Internal use only.
Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.
Hooks from the function
Returns
String. The page permalink.
Usage
_get_page_link( $post, $leavename, $sample );
- $post(int|WP_Post)
- Post ID or object.
Default: uses the global$post - $leavename(true|false)
- Whether to keep the page name.
Default:false - $sample(true|false)
- Whether it should be treated as a sample permalink.
Default:false
Notes
- Global. WP_Rewrite.
$wp_rewriteWordPress rewrite component.
Changelog
| Since 2.1.0 | Introduced. |
_get_page_link() get page link code WP 6.9.1
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 );
}