_get_page_link

Advertisement

Private Access Private Access

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.

Summery Summery

Retrieves the page permalink.

Syntax Syntax

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

Description Description

Ignores page_on_front. Internal use only.

Parameters Parameters

$post

(Optional) Post ID or object. Default uses the global $post.

Default value: false

$leavename

(Optional) Whether to keep the page name.

Default value: false

$sample

(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

	global $wp_rewrite;

	$post = get_post( $post );

	$draft_or_pending = in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ), true );

	$link = $wp_rewrite->get_page_permastruct();

	if ( ! empty( $link ) && ( ( isset( $post->post_status ) && ! $draft_or_pending ) || $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 );
}

Advertisement

Changelog Changelog

Changelog
Version Description
2.1.0 Introduced.

Advertisement

Leave a Reply