_get_page_link

The timeline below displays how wordpress function _get_page_link has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.7

/**
 * Retrieves the page permalink.
 *
 * Ignores page_on_front. Internal use only.
 *
 * @since 2.1.0
 * @access private
 *
 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
 *
 * @param int|WP_Post $post      Optional. Post ID or object. Default uses the global `$post`.
 * @param bool        $leavename Optional. Whether to keep the page name. Default false.
 * @param bool        $sample    Optional. Whether it should be treated as a sample permalink.
 *                               Default false.
 * @return string The page permalink.
 */
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);
}

WordPress Version: 5.5

/**
 * Retrieves the page permalink.
 *
 * Ignores page_on_front. Internal use only.
 *
 * @since 2.1.0
 * @access private
 *
 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
 *
 * @param int|WP_Post $post      Optional. Post ID or object. Default uses the global `$post`.
 * @param bool        $leavename Optional. Whether to keep the page name. Default false.
 * @param bool        $sample    Optional. Whether it should be treated as a sample permalink.
 *                               Default false.
 * @return string The page permalink.
 */
function _get_page_link($post = false, $leavename = false, $sample = false)
{
    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);
}

WordPress Version: 5.3

/**
 * Retrieves the page permalink.
 *
 * Ignores page_on_front. Internal use only.
 *
 * @since 2.1.0
 * @access private
 *
 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
 *
 * @param int|WP_Post $post      Optional. Post ID or object. Default uses the global `$post`.
 * @param bool        $leavename Optional. Whether to keep the page name. Default false.
 * @param bool        $sample    Optional. Whether it should be treated as a sample permalink.
 *                               Default false.
 * @return string The page permalink.
 */
function _get_page_link($post = false, $leavename = false, $sample = false)
{
    global $wp_rewrite;
    $post = get_post($post);
    $draft_or_pending = in_array($post->post_status, array('draft', 'pending', 'auto-draft'));
    $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);
}

WordPress Version: 4.6

/**
 * Retrieves the page permalink.
 *
 * Ignores page_on_front. Internal use only.
 *
 * @since 2.1.0
 * @access private
 *
 * @global WP_Rewrite $wp_rewrite
 *
 * @param int|WP_Post $post      Optional. Post ID or object. Default uses the global `$post`.
 * @param bool        $leavename Optional. Whether to keep the page name. Default false.
 * @param bool        $sample    Optional. Whether it should be treated as a sample permalink.
 *                               Default false.
 * @return string The page permalink.
 */
function _get_page_link($post = false, $leavename = false, $sample = false)
{
    global $wp_rewrite;
    $post = get_post($post);
    $draft_or_pending = in_array($post->post_status, array('draft', 'pending', 'auto-draft'));
    $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);
}

WordPress Version: 4.3

/**
 * Retrieve the page permalink.
 *
 * Ignores page_on_front. Internal use only.
 *
 * @since 2.1.0
 * @access private
 *
 * @global WP_Rewrite $wp_rewrite
 *
 * @param int|object $post      Optional. Post ID or object.
 * @param bool       $leavename Optional. Leave name.
 * @param bool       $sample    Optional. Sample permalink.
 * @return string The page permalink.
 */
function _get_page_link($post = false, $leavename = false, $sample = false)
{
    global $wp_rewrite;
    $post = get_post($post);
    $draft_or_pending = in_array($post->post_status, array('draft', 'pending', 'auto-draft'));
    $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);
    }
    /**
     * Filter 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);
}

WordPress Version: 4.1

/**
 * Retrieve the page permalink.
 *
 * Ignores page_on_front. Internal use only.
 *
 * @since 2.1.0
 * @access private
 *
 * @param int|object $post Optional. Post ID or object.
 * @param bool $leavename Optional. Leave name.
 * @param bool $sample Optional. Sample permalink.
 * @return string The page permalink.
 */
function _get_page_link($post = false, $leavename = false, $sample = false)
{
    global $wp_rewrite;
    $post = get_post($post);
    $draft_or_pending = in_array($post->post_status, array('draft', 'pending', 'auto-draft'));
    $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);
    }
    /**
     * Filter 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);
}

WordPress Version: 3.9

/**
 * Retrieve the page permalink.
 *
 * Ignores page_on_front. Internal use only.
 *
 * @since 2.1.0
 * @access private
 *
 * @param int|object $post Optional. Post ID or object.
 * @param bool $leavename Optional. Leave name.
 * @param bool $sample Optional. Sample permalink.
 * @return string
 */
function _get_page_link($post = false, $leavename = false, $sample = false)
{
    global $wp_rewrite;
    $post = get_post($post);
    $draft_or_pending = in_array($post->post_status, array('draft', 'pending', 'auto-draft'));
    $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);
    }
    /**
     * Filter 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);
}

WordPress Version: 3.7

/**
 * Retrieve the page permalink.
 *
 * Ignores page_on_front. Internal use only.
 *
 * @since 2.1.0
 * @access private
 *
 * @param int|object $post Optional. Post ID or object.
 * @param bool $leavename Optional. Leave name.
 * @param bool $sample Optional. Sample permalink.
 * @return string
 */
function _get_page_link($post = false, $leavename = false, $sample = false)
{
    global $wp_rewrite;
    $post = get_post($post);
    $draft_or_pending = in_array($post->post_status, array('draft', 'pending', 'auto-draft'));
    $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);
    }
    return apply_filters('_get_page_link', $link, $post->ID);
}