Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#34361 closed enhancement (duplicate)

Embed shortcode is not working in text widgets

Reported by: surbma's profile Surbma 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)

#1 follow-up: @swissspidy
9 years ago

Shortcodes aren't enabled for text widgets by design.

AFAIK [embed] isn't a "normal" shortcode and running the text through do_shortcode is not enough. Using the WP_Embed::run_shortcode method should work though. Note that the output isn't cached when not using in a post.

#2 in reply to: ↑ 1 @Surbma
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 @swissspidy
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.

Last edited 9 years ago by swissspidy (previous) (diff)

#4 @Surbma
9 years ago

Thank you for all the informations! I got some point of this issue from the other ticket.

FYI the example code is not working.

Note: See TracTickets for help on using tickets.