Title: get_post_embed_html
Published: December 9, 2015
Last modified: August 20, 2026

---

# get_post_embed_html( int $width, int $height, int|WP_Post|null $post = null ): string|false

## In this article

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

Retrieves the embed code for a specific post.

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

 `$width`intrequired

The width for the response.

`$height`intrequired

The height for the response.

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

Post ID or object. Default is global `$post`.

Default:`null`

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

 string|false Embed code on success, false if post doesn’t exist.

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

    ```php
    function get_post_embed_html( $width, $height, $post = null ) {
    	$post = get_post( $post );

    	if ( ! $post ) {
    		return false;
    	}

    	$embed_url = get_post_embed_url( $post );

    	$secret     = wp_generate_password( 10, false );
    	$embed_url .= "#?secret={$secret}";

    	$output = sprintf(
    		'<blockquote class="wp-embedded-content" data-secret="%1$s"><a href="%2$s">%3$s</a></blockquote>',
    		esc_attr( $secret ),
    		esc_url( get_permalink( $post ) ),
    		get_the_title( $post )
    	);

    	$output .= sprintf(
    		'<iframe sandbox="allow-scripts" security="restricted" src="%1$s" width="%2$d" height="%3$d" title="%4$s" data-secret="%5$s" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" class="wp-embedded-content"></iframe>',
    		esc_url( $embed_url ),
    		absint( $width ),
    		absint( $height ),
    		esc_attr(
    			sprintf(
    				/* translators: 1: Post title, 2: Site title. */
    				__( '&#8220;%1$s&#8221; &#8212; %2$s' ),
    				get_the_title( $post ),
    				get_bloginfo( 'name' )
    			)
    		),
    		esc_attr( $secret )
    	);

    	/*
    	 * Note that the script must be placed after the <blockquote> and <iframe> due to a regexp parsing issue in
    	 * `wp_filter_oembed_result()`. Because of the regex pattern starts with `|(<blockquote>.*?</blockquote>)?.*|`
    	 * wherein the <blockquote> is marked as being optional, if it is not at the beginning of the string then the group
    	 * will fail to match and everything will be matched by `.*` and not included in the group. This regex issue goes
    	 * back to WordPress 4.4, so in order to not break older installs this script must come at the end.
    	 */
    	$js_path = '/js/wp-embed' . wp_scripts_get_suffix() . '.js';
    	$output .= wp_get_inline_script_tag(
    		trim( file_get_contents( ABSPATH . WPINC . $js_path ) ) . "\n//# sourceURL=" . esc_url_raw( includes_url( $js_path ) )
    	);

    	/**
    	 * Filters the embed HTML output for a given post.
    	 *
    	 * @since 4.4.0
    	 *
    	 * @param string  $output The default iframe tag to display embedded content.
    	 * @param WP_Post $post   Current post object.
    	 * @param int     $width  Width of the response.
    	 * @param int     $height Height of the response.
    	 */
    	return apply_filters( 'embed_html', $output, $post, $width, $height );
    }
    ```

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

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

 [apply_filters( ’embed_html’, string $output, WP_Post $post, int $width, int $height )](https://developer.wordpress.org/reference/hooks/embed_html/)

Filters the embed HTML output for a given post.

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

| Uses | Description | 
| [wp_get_inline_script_tag()](https://developer.wordpress.org/reference/functions/wp_get_inline_script_tag/)`wp-includes/script-loader.php` |

Constructs an inline script tag.

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

Returns the suffix that can be used for the scripts.

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

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

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

Sanitizes a URL for database or redirect usage.

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

Generates a random password drawn from the defined set of characters.

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

Retrieves the URL to the includes directory.

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

Retrieves the post title.

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

Retrieves the translation of $text.

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

Escaping for HTML attributes.

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

Checks and cleans a URL.

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

Retrieves information about the current site.

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

Converts a value to non-negative integer.

  | 
| [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_post()](https://developer.wordpress.org/reference/functions/get_post/)`wp-includes/post.php` |

Retrieves post data given a post ID or post object.

  |

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

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

Prints the necessary markup for the embed sharing dialog.

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

Filters the oEmbed response data to return an iframe embed code.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_post_embed_html/?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_html%2F)
before being able to contribute a note or feedback.