get_post_embed_url

Retrieves the URL to embed a specific post in an iframe.

Description

(string|false) get_post_embed_url( (null) $post = null ); 

Returns (string|false)

The post embed URL on success, false if the post doesn't exist.

Parameters (1)

0. $post — Optional. (null) => null
Post ID or object. Defaults to the current post.

Usage

  1. if ( !function_exists( 'get_post_embed_url' ) ) { 
  2. require_once ABSPATH . WPINC . '/embed.php'; 
  3.  
  4. // Optional. Post ID or object. Defaults to the current post. 
  5. $post = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_post_embed_url($post); 
  9.  

Defined (1)

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

/wp-includes/embed.php  
  1. function get_post_embed_url( $post = null ) { 
  2. $post = get_post( $post ); 
  3.  
  4. if ( ! $post ) { 
  5. return false; 
  6.  
  7. $embed_url = trailingslashit( get_permalink( $post ) ) . user_trailingslashit( 'embed' ); 
  8. $path_conflict = get_page_by_path( str_replace( home_url(), '', $embed_url ), OBJECT, get_post_types( array( 'public' => true ) ) ); 
  9.  
  10. if ( ! get_option( 'permalink_structure' ) || $path_conflict ) { 
  11. $embed_url = add_query_arg( array( 'embed' => 'true' ), get_permalink( $post ) ); 
  12.  
  13. /** 
  14. * Filters the URL to embed a specific post. 
  15. * @since 4.4.0 
  16. * @param string $embed_url The post embed URL. 
  17. * @param WP_Post $post The corresponding post object. 
  18. */ 
  19. return esc_url_raw( apply_filters( 'post_embed_url', $embed_url, $post ) );