get_post_embed_url() WordPress Function

The get_post_embed_url() function retrieves the URL toembed a post. This function is used when the post is to be embedded on another site. The function takes the post ID as a parameter and returns the post embed URL.

get_post_embed_url( int|WP_Post $post = null ) #

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


Parameters

$post

(int|WP_Post)(Optional) Post ID or object. Defaults to the current post.

Default value: null


Top ↑

Return

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


Top ↑

Source

File: wp-includes/embed.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 esc_url_raw( apply_filters( 'post_embed_url', $embed_url, $post ) );
}


Top ↑

Changelog

Changelog
VersionDescription
4.4.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.