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

_get_page_link() WordPress Function

The get_page_link() function is used to retrieve the permalink for a page. This function is useful when you need to create a link to a page but don't have the page ID.

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

Retrieves the page permalink.


Description

Ignores page_on_front. Internal use only.


Top ↑

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


Top ↑

Return

(string) The page permalink.


Top ↑

Source

File: wp-includes/link-template.php

function _get_page_link( $post = false, $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 );
}


Top ↑

Changelog

Changelog
VersionDescription
2.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More