get_post_embed_url

函式
get_post_embed_url ( $post = null )
引數
  • (int|WP_Post) $post Optional. Post ID or object. Defaults to the current post.
    Required:
    Default: null
返回值
  • (string|false) The post embed URL on success, false if the post doesn't exist.
定義位置
相關方法
get_post_embed_htmlget_home_urlget_site_urlget_sitemap_urlget_post_meta
引入
4.4.0
棄用
-

get_post_embed_url函式用於檢索給定文章的嵌入內容的url。它只接受一個引數,即文章的ID。然後可以使用URL使用適當的HTML標記嵌入內容。

檢索在iframe中嵌入一個特定文章的URL。

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 sanitize_url( apply_filters( 'post_embed_url', $embed_url, $post ) );
}

常見問題

FAQs
檢視更多 >