WP_Embed::run_shortcode() WordPress Method

The WP_Embed::run_shortcode() method allows you to run a shortcode through the WordPress shortcode API. This is useful for when you want to embed a shortcode in a post or page.

WP_Embed::run_shortcode( string $content ) #

Processes the [embed] shortcode.


Description

Since the shortcode needs to be run earlier than other shortcodes, this function removes all existing shortcodes, registers the shortcode, calls do_shortcode(), and then re-registers the old shortcodes.


Top ↑

Parameters

$content

(string)(Required)Content to parse.


Top ↑

Return

(string) Content with shortcode parsed.


Top ↑

Source

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

	public function run_shortcode( $content ) {
		global $shortcode_tags;

		// Back up current registered shortcodes and clear them all out.
		$orig_shortcode_tags = $shortcode_tags;
		remove_all_shortcodes();

		add_shortcode( 'embed', array( $this, 'shortcode' ) );

		// Do the shortcode (only the [embed] one is registered).
		$content = do_shortcode( $content, true );

		// Put the original shortcodes back.
		$shortcode_tags = $orig_shortcode_tags;

		return $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.