get_page_uri

Build the URI path for a page.

Description

(string|false) get_page_uri( (int) $page = 0 ); 

Sub pages will be in the directory under the parent page post name.

Returns (string|false)

Page URI, false on error.

Parameters (1)

0. $page — Optional. (int)
Page ID or WP_Post object. Default is global $post.

Usage

  1. if ( !function_exists( 'get_page_uri' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // Optional. Page ID or WP_Post object. Default is global $post. 
  5. $page = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_page_uri($page); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/post.php  
  1. function get_page_uri( $page = 0 ) { 
  2. if ( ! $page instanceof WP_Post ) { 
  3. $page = get_post( $page ); 
  4.  
  5. if ( ! $page ) 
  6. return false; 
  7.  
  8. $uri = $page->post_name; 
  9.  
  10. foreach ( $page->ancestors as $parent ) { 
  11. $parent = get_post( $parent ); 
  12. if ( $parent && $parent->post_name ) { 
  13. $uri = $parent->post_name . '/' . $uri; 
  14.  
  15. /** 
  16. * Filters the URI for a page. 
  17. * @since 4.4.0 
  18. * @param string $uri Page URI. 
  19. * @param WP_Post $page Page object. 
  20. */ 
  21. return apply_filters( 'get_page_uri', $uri, $page );