WP_Embed::autoembed() WordPress Method

The WP_Embed::autoembed() method is used to automatically embeds URLs in content. This is done by converting the URL into an embed code and then inserting it into the content. This is useful for sites that want to automatically embed media from other sites, such as YouTube or Vimeo.

WP_Embed::autoembed( string $content ) #

Passes any unlinked URLs that are on their own line to WP_Embed::shortcode() for potential embedding.


Description

Top ↑

See also


Top ↑

Parameters

$content

(string)(Required)The content to be searched.


Top ↑

Return

(string) Potentially modified $content.


Top ↑

Source

File: wp-includes/class-wp-embed.php

	public function autoembed( $content ) {
		// Replace line breaks from all HTML elements with placeholders.
		$content = wp_replace_in_html_tags( $content, array( "\n" => '<!-- wp-line-break -->' ) );

		if ( preg_match( '#(^|\s|>)https?://#i', $content ) ) {
			// Find URLs on their own line.
			$content = preg_replace_callback( '|^(\s*)(https?://[^\s<>"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content );
			// Find URLs in their own paragraph.
			$content = preg_replace_callback( '|(<p(?: [^>]*)?>\s*)(https?://[^\s<>"]+)(\s*<\/p>)|i', array( $this, 'autoembed_callback' ), $content );
		}

		// Put the line breaks back.
		return str_replace( '<!-- wp-line-break -->', "\n", $content );
	}

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.