get_post_embed_url()
Gets the URL to be used in an iframe for embedding the specified post on another site (oEmbed format).
What is Embed read here: oEmbed in WordPress
To embed a post from another site on WordPress into your site, you need to add the post's URL to the content of your post. WordPress will automatically process the URL.
Uses: get_permalink()
Used By: get_post_embed_html()
Hooks from the function
Returns
String|false. oEmbed URL of the post or false if the post does not exist.
Usage
get_post_embed_url( $post );
- $post(integer/WP_Post)
- ID or post object, the oEmbed url of which needs to be obtained.
Default: null (the current post in the loop)
Examples
#1 What oEmbed link looks like
echo get_post_embed_url( 1 ); // outputs: http://example.com/post-name/embed
#2 Finished embedded view
As an example, let's take the article on this site: https://wp-kama.com/handbook/cheatsheet and create a manual embed for it, using this URL https://wp-kama.com/handbook/cheatsheet/embed
<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" src="/handbook/cheatsheet/embed" width="600" height="350" style="max-width:600px" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
The result will be this insertion:
The following function exists to create an iframe block automatically for the specified post: get_post_embed_html()
Changelog
| Since 4.4.0 | Introduced. |