close

is_post_embeddable( int|WP_Post|null $post = null ): bool

Determines whether a post is embeddable.

Parameters

$postint|WP_Post|nulloptional
Post ID or WP_Post object. Defaults to global $post.

Default:null

Return

bool Whether the post should be considered embeddable.

Source

function is_post_embeddable( $post = null ) {
	$post = get_post( $post );

	if ( ! $post ) {
		return false;
	}

	$post_type = get_post_type_object( $post->post_type );

	if ( ! $post_type ) {
		return false;
	}

	$is_embeddable = $post_type->embeddable;

	/**
	 * Filter whether a post is embeddable.
	 *
	 * @since 6.8.0
	 *
	 * @param bool    $is_embeddable Whether the post is embeddable.
	 * @param WP_Post $post          Post object.
	 */
	return apply_filters( 'is_post_embeddable', $is_embeddable, $post );
}

Hooks

apply_filters( ‘is_post_embeddable’, bool $is_embeddable, WP_Post $post )

Filter whether a post is embeddable.

Changelog

VersionDescription
6.8.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    is_post_embeddable() checks whether a post is publicly viewable and of an embeddable post type. This is commonly used in oEmbed handlers and custom preview generators to ensure a post can be safely embedded before outputting embed HTML.

    Example: Only show embed link if the post is embeddable

    $post_id = get_the_ID();
    if ( is_post_embeddable( $post_id ) ) {
        echo '<a href="' . esc_url( get_permalink( $post_id ) ) . '">' .
             esc_html__( 'Embed this post', 'your-textdomain' ) .
             '</a>';
    } else {
        echo esc_html__( 'Embedding not allowed for this post.', 'your-textdomain' );
    }

    This function helps prevent attempting to embed protected, private, or unsupported post types. It’s particularly useful in custom oEmbed endpoints or when building embed previews manually.

You must log in before being able to contribute a note or feedback.