#34361 closed enhancement (duplicate)
Embed shortcode is not working in text widgets
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.3.1 |
Component: | Widgets | Keywords: | |
Focuses: | Cc: |
Description
The [embed] shortcode is only working in a post content, but not working in a text widget.
We presuppose, that shortcodes are enabled in text widgets with the right filter.
Change History (4)
#2
in reply to:
↑ 1
@
9 years ago
Replying to swissspidy:
Using the
WP_Embed::run_shortcode
method should work though.
Thank you for your reply! Can you please give a working example code?
Is it something, that never will change to make it easy to use in a text widget?
#3
@
9 years ago
- Component changed from Embeds to Widgets
- Milestone Awaiting Review deleted
- Resolution set to duplicate
- Status changed from new to closed
Thank you for your reply! Can you please give a working example code?
Something like this should work (untested!):
<?php function wp34361_widget_text_embeds($text) { global $wp_embed; return $wp_embed->run_shortcode( $text ); } add_filter( 'widget_text', 'wp34361_widget_text_embeds' );
If it doesn't, that's because of the caching in post meta. See https://core.trac.wordpress.org/ticket/10457#comment:33
See also WP_Embed::__construct
for the various hooks that are used for embeds.
Is it something, that never will change to make it easy to use in a text widget?
Shortcodes in widgets are being discussed in #10457. There are some edge cases that need to be considered, like the post meta cache for embeds.
Closing this ticket as a duplicate.
Shortcodes aren't enabled for text widgets by design.
AFAIK
[embed]
isn't a "normal" shortcode and running the text throughdo_shortcode
is not enough. Using theWP_Embed::run_shortcode
method should work though. Note that the output isn't cached when not using in a post.