get_page_link()

You are here:

get_page_link( int|WP_Post $post = falsebool $leavename = falsebool $sample = false )

Retrieves the permalink for the current page or page ID.

CONTENTS

  • Description
  • Parameters
  • Return
  • Source
  • Related
    • Uses
    • Used By
  • Changelog
  • User Contributed Notes

Description Description

Respects page_on_front. Use this one.


Top ↑

Parameters 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 Return

(string) The page permalink.


Top ↑

Source Source

File: wp-includes/link-template.php

331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
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 );
}


Top ↑

Changelog Changelog

Changelog
VersionDescription
1.5.0Introduced.
Was this article helpful?
Dislike 0
Views: 5

Cart

Log in

Create an Account
Back to Top