get_post_embed_html( int $width, int $height, int|WP_Post $post = null )

Retrieves the embed code for a specific post.


Parameters

$width

(Required) The width for the response.

$height

(Required) The height for the response.

$post

(Optional) Post ID or object. Default is global $post.

Default value: null


Return

(string|false) Embed code on success, false if post doesn't exist.


Source

File: wp-includes/embed.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 );

	$output = '<blockquote class="wp-embedded-content"><a href="' . esc_url( get_permalink( $post ) ) . '">' . get_the_title( $post ) . "</a></blockquote>\n";

	$output .= "<script type='text/javascript'>\n";
	$output .= "<!--//--><![CDATA[//><!--\n";
	if ( SCRIPT_DEBUG ) {
		$output .= file_get_contents( ABSPATH . WPINC . '/js/wp-embed.js' );
	} else {
		/*
		 * If you're looking at a src version of this file, you'll see an "include"
		 * statement below. This is used by the `grunt build` process to directly
		 * include a minified version of wp-embed.js, instead of using the
		 * file_get_contents() method from above.
		 *
		 * If you're looking at a build version of this file, you'll see a string of
		 * minified JavaScript. If you need to debug it, please turn on SCRIPT_DEBUG
		 * and edit wp-embed.js directly.
		 */
		$output .=<<<JS
		!function(e,t){"use strict";var r=!1,a=!1;if(t.querySelector)if(e.addEventListener)r=!0;if(e.wp=e.wp||{},!e.wp.receiveEmbedMessage)if(e.wp.receiveEmbedMessage=function(r){var a=r.data;if(a)if(a.secret||a.message||a.value)if(!/[^a-zA-Z0-9]/.test(a.secret)){var i,s,n,o,c,d=t.querySelectorAll('iframe[data-secret="'+a.secret+'"]'),l=t.querySelectorAll('blockquote[data-secret="'+a.secret+'"]');for(i=0;i<l.length;i++)l[i].style.display="none";for(i=0;i<d.length;i++)if(s=d[i],r.source===s.contentWindow){if(s.removeAttribute("style"),"height"===a.message){if((n=parseInt(a.value,10))>1e3)n=1e3;else if(~~n<200)n=200;s.height=n}if("link"===a.message)if(o=t.createElement("a"),c=t.createElement("a"),o.href=s.getAttribute("src"),c.href=a.value,c.host===o.host)if(t.activeElement===s)e.top.location.href=a.value}}},r)e.addEventListener("message",e.wp.receiveEmbedMessage,!1),t.addEventListener("DOMContentLoaded",i,!1),e.addEventListener("load",i,!1);function i(){if(!a){a=!0;var e,r,i,s,n=-1!==navigator.appVersion.indexOf("MSIE 10"),o=!!navigator.userAgent.match(/Trident.*rv:11\./),c=t.querySelectorAll("iframe.wp-embedded-content");for(r=0;r<c.length;r++){if(!(i=c[r]).getAttribute("data-secret"))s=Math.random().toString(36).substr(2,10),i.src+="#?secret="+s,i.setAttribute("data-secret",s);if(n||o)(e=i.cloneNode(!0)).removeAttribute("security"),i.parentNode.replaceChild(e,i)}}}}(window,document);
JS;
	}
	$output .= "\n//--><!]]>";
	$output .= "\n</script>";

	$output .= sprintf(
		'<iframe sandbox="allow-scripts" security="restricted" src="%1$s" width="%2$d" height="%3$d" title="%4$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 name */
				__( '&#8220;%1$s&#8221; &#8212; %2$s' ),
				get_the_title( $post ),
				get_bloginfo( 'name' )
			)
		)
	);

	/**
	 * Filters the embed HTML output for a given post.
	 *
	 * @since WP-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 );
}


Changelog

Changelog
Version Description
WP-4.4.0 Introduced.