Opened 3 months ago
Last modified 3 months ago
#23431 new feature request
[embed] shortcode doesn't work with do_shortcode()
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Embeds | Version: | 3.5 |
| Severity: | normal | Keywords: | has-patch |
| Cc: |
Description
It would be preferable to use the [embed] shortcode through do_shortcode rather than apply_filters( 'the_content',... in order to avoid sharing plugins, related posts plugins etc appending content to something that could simple be post meta, i.e. looking to convert a youtube url to a video.
Attachments (1)
Change History (8)
comment:2
jtsternberg — 3 months ago
No, that method doesn't work because it's not a proper static method and uses the $this variable which is unavailable. I CAN do
$embed = new WP_Embed(); $video = $embed->run_shortcode( '[embed width="890"]'. esc_url( $video_url ) .'[/embed]' );
But that definitely seems like overkill to me.
comment:3
jtsternberg — 3 months ago
Ok, digging a bit further, I realized the WP_Embed class is initialized as a global variable so is accessible to me via
$GLOBALS['wp_embed']->run_shortcode( '[embed width="890"]'. esc_url( $video_url ) .'[/embed]' );
So pardon my interruption here. :)
Curious, should we document that in the codex?
comment:4
jtsternberg — 3 months ago
Ok, another thought regarding the point of this ticket originally: it seems plausible that we could still enable this featured through do_shortcode() by checking for the [embed] shortcode, and then running this method. I'll throw up a patch if I get a chance.
Well, yes, working code would be global $wp_embed; $wp_embed->run_shortcode( $whatever );. I'd check out the docs for the method - I think you'll find them helpful.
jtsternberg — 3 months ago
Simple check for the [embed] shortcode that allows filtering via do_shortcode()
comment:6
SergeyBiryukov — 3 months ago
- Component changed from General to Embeds
- Version changed from trunk to 3.5
comment:7
jtsternberg — 3 months ago
- Keywords has-patch added; needs-patch removed

FWIW, you can do it through WP_Embed::run_shortcode().