+44 0330 223 3428
Call Us
+44 0330 223 3428

WPTavern: WordPress 4.9 Will Support Shortcodes and Embedded Media in the Text Widget

WPTavern: WordPress 4.9 Will Support Shortcodes and Embedded Media in the Text Widget

WordPress 4.8 brought TinyMCE to the core Text widget, along with brand new Image, Video, and Audio media widgets. The upcoming 4.9 release builds on this progress and will introduce some long-awaited improvements to Text widget. Users will finally be able to use shortcodes in the Text widget without the help of additional code from plugins or themes.

This new feature is the answer to an eight-year-old ticket requesting shortcode support inside the Text widget. Weston Ruter broke down the technical details in the dev note for the feature, explaining why it took so long to find a solution:

One reason for the long delay with adding shortcode support in Text widgets was due to many shortcodes looking for a global $post when they run. Since the global $post varies depending on whatever the query is, the shortcodes in a Text widget could render wildly different on different templates of a site. The solution worked out was to temporarily nullify the global $post before doing the shortcodes so that they will consistently have the same global state, with this global $post then restored after the shortcodes are done.

Hundreds of thousands of WordPress installations currently use a plugin to add shortcode support to widgets. Contributors to 4.9 have taken this into account so that updating will not cause unexpected issues.

“If a plugin has added do_shortcode() to widget_text then this filter will be suspended while the widget runs to prevent shortcodes from being applied twice,” Ruter said.

In addition to the new core gallery widget landing in 4.9, this release will also allow users to embed media in the Text widget. A new “Add Media” button is available, making it easy for users to insert images, audio, galleries, and videos, along with text and other content. WordPress 4.9 also adds support for oEmbeds in the Text widget and the Video widget has been updated with expanded support for any oEmbed provider for video.

Little enhancements like these make it easier for users to update their own websites without having to hire a developer or add extra plugins for things that should be simple. The improvements to widgets have also been implemented in such a way that users will be more prepared for how Gutenberg will handle media.

“The media-specific widgets are closely aligned with blocks in Gutenberg; the existence of media inside the Text widget will align with eventual nested blocks in Gutenberg, and would be treated as Classic Text blocks in any future migration from widgets to blocks,” Ruter said.

WordPress 4.9 will improve the experience of switching between themes by including logic that is better at mapping widgets between two themes’ widget areas. This release will also improve the UI for updating and saving widgets in the admin screen. It adds an indicator that shows whether or not widget changes have been saved, as well as a notice if the user attempts to leave the page with unsaved changes.

Source: WordPress

Related Post
WPTavern: WPWeekly Episode 292 – Recap of WooConf and CaboPress

WPTavern: WPWeekly Episode 292 – Recap of WooConf and CaboPress In this episode, John James Jacoby and I are joined by Cody Landefeld, co-founder of Mode Effect. Landefeld described his experience attending WooConf as we reviewed highlights from the State of the Woo. We also discussed WooCommerce retiring its Canvas theme in favor of Storefront. Jacoby […]

Read more
WPTavern: Goodnight Firebug

WPTavern: Goodnight Firebug Twitter is lighting up with sentimental Firebug remembrances today after Mozilla announced it will reach end-of-life in the Firefox browser next month. Firebug was the first browser-based tool that allowed developers to easily inspect HTML and debug JS. It was discontinued as a separate add-on and merged into Firefox DevTools in 2016 […]

Read more
WPTavern: WordPress 4.9 Beta 4 Removes ‘Try Gutenberg’ Call to Action

WPTavern: WordPress 4.9 Beta 4 Removes ‘Try Gutenberg’ Call to Action WordPress beta releases typically don’t generate controversy but in WordPress 4.9 Beta 3, a call to action was added to the dashboard that encouraged users to install and activate Gutenberg. Try Gutenberg Call to Action Members of the WordPress community raised concerns that clients […]

Read more