Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

Så här aktiverar du oEmbed i WordPress textwidgetar

Nyligen frågade en av våra användare oss hur man aktiverar oEmbed i WordPress textwidgets. oEmbed är ett protokoll som gör att din blogg kan be en oEmbed aktiverad website att tillhandahålla HTML som behövs för att bädda in dynamiskt content. Med enkla ord, det allow you att bara klistra in en YouTube video URL i ett blogginlägg och låt WordPress embed den automatiskt. Du kan justera oEmbeds maximala bredd manuellt, eller dynamiskt ändra oEmbed-innehållets bredd och höjd. Du kan dock ej bädda in content i en textwidget med oEmbed. I den här artikeln visar vi dig hur du aktiverar oEmbed i WordPress textwidgets.

Allt du behöver göra är att add to följande kod i ditt temas functions.php-fil eller ett site-specifikt plugin:

1
2
add_filter( 'widget_text', array( $wp_embed, 'run_shortcode' ), 8 );
add_filter( 'widget_text', array( $wp_embed, 'autoembed'), 8 );

När du har gjort det, då är du klar. Du har utan problem aktiverat oEmbed för textwidgets. You can head over to Appearance ” Widgetar to test it. Lägg bara till en Youtube video URL i din text widgetar, och titta på magin.

För de av er som vill veta vad den här koden gör, lägger den helt enkelt till ett filter widget_text som allow textwidgets att run shortcode för oEmbed och auto-embed content.

För dig som inte gillar att hantera kod, kan du helt enkelt aktivera Text Widget oEmbed plugin. Det gör bokstavligen samma sak. Pluginet har bara 2 rader kod som vi delade ovan.

Vi hoppas att den här artikeln hjälpte dig att aktivera oEmbed i textwidgets. Om du har några frågor eller kommentarer, vänligen låt oss veta genom att lämna en kommentar under.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

2 kommentarerLeave a Reply

  1. Jonathan

    Is this code not enough?

    add_filter ('widget_text', array ($ wp_embed, 'autoembed'), 8);

  2. Fernando

    Thanks for the tip but has a problem, that the media content doesn’t adapt to the sidebar width, something that we can control with the embed code and not with the plugin or the code.

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.