Title: get_post_embed_url
Published: December 9, 2015
Last modified: February 24, 2026

---

# get_post_embed_url( int|WP_Post $post = null ): string|false

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/get_post_embed_url/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_post_embed_url/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_post_embed_url/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/get_post_embed_url/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/get_post_embed_url/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_post_embed_url/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/get_post_embed_url/?output_format=md#wp--skip-link--target)

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

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_post_embed_url/?output_format=md#parameters)󠁿

 `$post`int|[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)
optional

Post ID or object. Defaults to the current post.

Default:`null`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_post_embed_url/?output_format=md#return)󠁿

 string|false The post embed URL on success, false if the post doesn’t exist.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_post_embed_url/?output_format=md#source)󠁿

    ```php
    function get_post_embed_url( $post = null ) {
    	$post = get_post( $post );

    	if ( ! $post ) {
    		return false;
    	}

    	$embed_url     = trailingslashit( get_permalink( $post ) ) . user_trailingslashit( 'embed' );
    	$path_conflict = get_page_by_path( str_replace( home_url(), '', $embed_url ), OBJECT, get_post_types( array( 'public' => true ) ) );

    	if ( ! get_option( 'permalink_structure' ) || $path_conflict ) {
    		$embed_url = add_query_arg( array( 'embed' => 'true' ), get_permalink( $post ) );
    	}

    	/**
    	 * Filters the URL to embed a specific post.
    	 *
    	 * @since 4.4.0
    	 *
    	 * @param string  $embed_url The post embed URL.
    	 * @param WP_Post $post      The corresponding post object.
    	 */
    	return sanitize_url( apply_filters( 'post_embed_url', $embed_url, $post ) );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/embed.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/embed.php#L419)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/embed.php#L419-L442)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/get_post_embed_url/?output_format=md#hooks)󠁿

 [apply_filters( ‘post_embed_url’, string $embed_url, WP_Post $post )](https://developer.wordpress.org/reference/hooks/post_embed_url/)

Filters the URL to embed a specific post.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_post_embed_url/?output_format=md#related)󠁿

| Uses | Description | 
| [user_trailingslashit()](https://developer.wordpress.org/reference/functions/user_trailingslashit/)`wp-includes/link-template.php` |

Retrieves a trailing-slashed string if the site is set for adding trailing slashes.

  | 
| [get_page_by_path()](https://developer.wordpress.org/reference/functions/get_page_by_path/)`wp-includes/post.php` |

Retrieves a page given its path.

  | 
| [trailingslashit()](https://developer.wordpress.org/reference/functions/trailingslashit/)`wp-includes/formatting.php` |

Appends a trailing slash.

  | 
| [sanitize_url()](https://developer.wordpress.org/reference/functions/sanitize_url/)`wp-includes/formatting.php` |

Sanitizes a URL for database or redirect usage.

  | 
| [add_query_arg()](https://developer.wordpress.org/reference/functions/add_query_arg/)`wp-includes/functions.php` |

Retrieves a modified URL query string.

  | 
| [home_url()](https://developer.wordpress.org/reference/functions/home_url/)`wp-includes/link-template.php` |

Retrieves the URL for the current site where the front end is accessible.

  | 
| [get_permalink()](https://developer.wordpress.org/reference/functions/get_permalink/)`wp-includes/link-template.php` |

Retrieves the full permalink for the current post or post ID.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [get_option()](https://developer.wordpress.org/reference/functions/get_option/)`wp-includes/option.php` |

Retrieves an option value based on an option name.

  | 
| [get_post()](https://developer.wordpress.org/reference/functions/get_post/)`wp-includes/post.php` |

Retrieves post data given a post ID or post object.

  | 
| [get_post_types()](https://developer.wordpress.org/reference/functions/get_post_types/)`wp-includes/post.php` |

Gets a list of all registered post type objects.

  |

[Show 9 more](https://developer.wordpress.org/reference/functions/get_post_embed_url/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_post_embed_url/?output_format=md#)

| Used by | Description | 
| [get_post_embed_html()](https://developer.wordpress.org/reference/functions/get_post_embed_html/)`wp-includes/embed.php` |

Retrieves the embed code for a specific post.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_post_embed_url/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_post_embed_url%2F)
before being able to contribute a note or feedback.