wp embed

Inspects oEmbed providers, clears embed cache, and more.

Commands Description
wp embed cache clear Deletes all oEmbed caches for a given post.
wp embed cache find Finds an oEmbed cache post ID for a given URL.
wp embed cache trigger Triggers the caching of all oEmbed results for a given post.
wp embed fetch Attempts to convert a URL into embed HTML.
wp embed handler list Lists all available embed handlers.
wp embed provider list Lists all available oEmbed providers.
wp embed provider match Gets the matching provider for a given URL.

Examples

# Clear cache for a post
$ wp embed cache clear 123
Success: Cleared oEmbed cache.

# Find cache post ID for a given URL.
$ wp embed cache find https://www.youtube.com/watch?v=dQw4w9WgXcQ --width=500
123

# Triggers cache for a post
$ wp embed cache trigger 456
Success: Caching triggered!

Source code of the commands


wp embed cache clear

Deletes all oEmbed caches for a given post.

oEmbed caches for a post are stored in the post's metadata.

Usage

wp embed cache clear {post_id}

You can specify global options and the following:

{post_id}
ID of the post to clear the cache for.

Examples

# Clear cache for a post
$ wp embed cache clear 123
Success: Cleared oEmbed cache.

wp embed cache find

Finds an oEmbed cache post ID for a given URL.

Starting with WordPress 4.9, embeds that aren't associated with a specific post will be cached in a new oembed_cache post type. There can be more than one such entry for a url depending on attributes and context.

Not to be confused with oEmbed caches for a given post which are stored in the post's metadata.

Usage

wp embed cache find {url} [--width={width}] [--height={height}] [--discover]

You can specify global options and the following:

{url}
URL to retrieve oEmbed data for.
[--width={width}]
Width of the embed in pixels. Part of cache key so must match. Defaults to content_width if set else 500px, so is theme and context dependent.
[--height={height}]
Height of the embed in pixels. Part of cache key so must match. Defaults to 1.5 * default width (content_width or 500px), to a maximum of 1000px.
[--discover]
Whether to search with the discover attribute set or not. Part of cache key so must match. If not given, will search with attribute: unset, '1', '0', returning first.

Examples

# Find cache post ID for a given URL.
$ wp embed cache find https://www.youtube.com/watch?v=dQw4w9WgXcQ --width=500
123

wp embed cache trigger

Triggers the caching of all oEmbed results for a given post.

oEmbed caches for a post are stored in the post's metadata.

Usage

wp embed cache trigger {post_id}

You can specify global options and the following:

{post_id}
ID of the post to do the caching for.

Examples

# Triggers cache for a post
$ wp embed cache trigger 456
Success: Caching triggered!

wp embed fetch

Attempts to convert a URL into embed HTML.

In non-raw mode, starts by checking the URL against the regex of the registered embed handlers. If none of the regex matches and it's enabled, then the URL will be given to the WP_oEmbed class.

In raw mode, checks the providers directly and returns the data.

Usage

wp embed fetch {url} [--width={width}] [--height={height}] [--post-id={id}] [--discover] [--skip-cache] [--skip-sanitization] [--do-shortcode] [--limit-response-size={size}] [--raw] [--raw-format={json|xml}]

You can specify global options and the following:

{url}
URL to retrieve oEmbed data for.
[--width={width}]
Width of the embed in pixels.
[--height={height}]
Height of the embed in pixels.
[--post-id={id}]
Cache oEmbed response for a given post.
[--discover]
Enable oEmbed discovery. Defaults to true.
[--skip-cache]
Ignore already cached oEmbed responses. Has no effect if using the 'raw' option, which doesn't use the cache.
[--skip-sanitization]
Remove the filter that WordPress from 4.4 onwards uses to sanitize oEmbed responses. Has no effect if using the 'raw' option, which by-passes sanitization.
[--do-shortcode]
If the URL is handled by a registered embed handler and returns a shortcode, do shortcode and return result. Has no effect if using the 'raw' option, which by-passes handlers.
[--limit-response-size={size}]
Limit the size of the resulting HTML when using discovery. Default 150 KB (the standard WordPress limit). Not compatible with 'no-discover'.
[--raw]
Return the raw oEmbed response instead of the resulting HTML. Ignores the cache and does not sanitize responses or use registered embed handlers.
[--raw-format={json|xml}]

Render raw oEmbed data in a particular format. Defaults to json. Can only be specified in conjunction with the 'raw' option.

Can be:

  • json
  • xml

Examples

# Get embed HTML for a given URL.
$ wp embed fetch https://www.youtube.com/watch?v=dQw4w9WgXcQ
<iframe width="525" height="295" src="https://www.youtube.com/embed/dQw4w9WgXcQ?feature=oembed" ...
# Get raw oEmbed data for a given URL.
$ wp embed fetch https://www.youtube.com/watch?v=dQw4w9WgXcQ --raw
{"author_url":"https:\/\/www.youtube.com\/user\/RickAstleyVEVO","width":525,"version":"1.0", ...

wp embed handler list

Lists all available embed handlers.

Usage

wp embed handler list [--field={field}] [--fields={fields}] [--format={format}]

You can specify global options and the following:

[--field={field}]
Display the value of a single field
[--fields={fields}]
Limit the output to specific fields.
[--format={format}]

Render output in a particular format.
Default: table
Can be:

  • table
  • csv
  • json

Available fields

These fields will be displayed by default for each handler:

  • id
  • regex

These fields are optionally available:

  • callback
  • priority

Examples

# List id,regex,priority fields of available handlers.
$ wp embed handler list --fields=priority,id
+----------+-------------------+
| priority | id                |
+----------+-------------------+
| 10       | youtube_embed_url |
| 9999     | audio             |
| 9999     | video             |

wp embed provider list

Lists all available oEmbed providers.

Usage

wp embed provider list [--field={field}] [--fields={fields}] [--format={format}] [--force-regex]

You can specify global options and the following:

[--field={field}]
Display the value of a single field
[--fields={fields}]
Limit the output to specific fields.
[--format={format}]

Render output in a particular format.
Default: table
Can be:

  • table
  • csv
  • json
[--force-regex]
Turn the asterisk-type provider URLs into regexes.

Available fields

These fields will be displayed by default for each provider:

  • format
  • endpoint

This field is optionally available:

  • regex

Examples

# List format,endpoint fields of available providers.
$ wp embed provider list --fields=format,endpoint
+------------------------------+-----------------------------------------+
| format                       | endpoint                                |
+------------------------------+-----------------------------------------+
| #https?://youtu\.be/.*#i     | https://www.youtube.com/oembed          |
| #https?://flic\.kr/.*#i      | https://www.flickr.com/services/oembed/ |
| #https?://wordpress\.tv/.*#i | https://wordpress.tv/oembed/            |

wp embed provider match

Gets the matching provider for a given URL.

Usage

wp embed provider match {url} [--discover] [--limit-response-size={size}] [--link-type={json|xml}]

You can specify global options and the following:

{url}
URL to retrieve provider for.
[--discover]
Whether to use oEmbed discovery or not. Defaults to true.
[--limit-response-size={size}]
Limit the size of the resulting HTML when using discovery. Default 150 KB (the standard WordPress limit). Not compatible with 'no-discover'.
[--link-type={json|xml}]

Whether to accept only a certain link type when using discovery. Defaults to any (json or xml), preferring json. Not compatible with 'no-discover'.

Can be:

  • json
  • xml

Examples

# Get the matching provider for the URL.
$ wp embed provider match https://www.youtube.com/watch?v=dQw4w9WgXcQ
https://www.youtube.com/oembed