I’ve used a trick for quite awhile that allows me to place shortcodes in the text widgets on my site.
WordPress 2.9 was released with the ability to auto-embed media, such as youtube videos, in posts by simply pasting a plain text URL into the post content. I have thought for some time that it would be really great to be able to borrow from the idea behind the shortcode in text widget trick to enable the same auto-embed functionality in my text widgets.
With the help of a couple of my fellow StudioPress forum moderators, Charles Clarkson and Gary Jones, I now have a solution! The YouTube video in the footer of this site, for example, is placed using the
PGNvZGU+W2VtYmVkXTwvY29kZT4=
shortcode to automatically embed the video.
This trick can be acomplished by adding the following code to the functions.php file in your sites active theme directory.
PGNvZGU+DQovL0VuYWJsZSBBdXRvRW1iZWRzIGZyb20gUGxhaW4gVGV4dCBVUkxzIGluIFRleHQgV2lkZ2V0cw0KYWRkX2ZpbHRlciggJ3dpZGdldF90ZXh0JywgYXJyYXkoICR3cF9lbWJlZCwgJ3J1bl9zaG9ydGNvZGUnICksIDggKTsNCmFkZF9maWx0ZXIoICd3aWRnZXRfdGV4dCcsIGFycmF5KCAkd3BfZW1iZWQsICdhdXRvZW1iZWQnKSwgOCApOw0KPC9jb2RlPg==This should allow both plain text urls in text widgets and the
PGNvZGU+W2VtYmVkXTwvY29kZT4=shortcode:
Examples:
PGNvZGU+aHR0cDovL3d3dy55b3V0dWJlLmNvbS93YXRjaD92PXltd2taQzVfaFk4PC9jb2RlPg==Would look like this:
PGNvZGU+W2VtYmVkIHdpZHRoPSIyNTAiIGhlaWdodD0iMTY1Il1odHRwOi8vd3d3LnlvdXR1YmUuY29tL3dhdGNoP3Y9eW13a1pDNV9oWThbL2VtYmVkXTwvY29kZT4=Would look like this:
Daisy…
Thanks for sharing this information. I have a Streamline theme. (I’m a bit new to this.)
Do I go to Appearance>editor>Templates> theme functions…and then paste the code at the bottom?
Also, to make sure…do I paste the following in it’s entirety?
//Enable AutoEmbeds from Plain Text URLs in Text Widgets
add_filter( ‘widget_text’, array( $wp_embed, ‘run_shortcode’ ), 8 );
add_filter( ‘widget_text’, array( $wp_embed, ‘autoembed’), 8 );
When it is completed can I simply paste the youtube link into the widget?
Thanks…Bob
In a Genesis Child Theme you can add the code add to functions.php in the child theme’s directory at the end of the file but before the final ?> if there is one.
Depending on the video you might want to use the
shortcode so that you can set a width otherwise the video may come out larger than your widget area width.
Daisy…
Good news! It’s working like a charm.
Thanks again…Bob
Thx! Great tip. Just what I was looking for