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

Come abilitare oEmbed nei widget di testo di WordPress

Recentemente, un nostro utente ci ha chiesto come abilitare oEmbed nei widget di testo di WordPress. oEmbed è un protocollo che permette al vostro blog di chiedere a un sito web abilitato a oEmbed di fornire l’HTML necessario per incorporare contenuti dinamici. In parole povere, permette di incollare l’URL di un video di YouTube in un articolo del blog e lasciare che WordPress lo incorpori automaticamente. È possibile regolare manualmente la larghezza massima di oEmbed o modificare dinamicamente la larghezza e l’altezza del contenuto di oEmbed. Tuttavia, non è possibile incorporare contenuti in un widget di testo utilizzando oEmbed. In questo articolo vi mostreremo come abilitare oEmbed nei widget di testo di WordPress.

Tutto ciò che dovete fare è aggiungere il seguente codice nel file functions.php del vostro tema o in un plugin specifico del sito:

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

Una volta fatto questo, il gioco è fatto. Avete abilitato oEmbed per i widget di testo. È possibile andare su Aspetto ” Widget per provarlo. Aggiungete semplicemente un URL di un video di Youtube nel widget di testo e osservate la magia.

Per chi volesse sapere cosa fa questo codice, aggiunge semplicemente un filtro widget_text che permette ai widget di testo di eseguire lo shortcode per oEmbed e di incorporare automaticamente il contenuto.

Per coloro che non amano avere a che fare con il codice, è sufficiente attivare il plugin Text Widget oEmbed. Fa letteralmente la stessa cosa. Il plugin ha solo 2 righe di codice che abbiamo condiviso sopra.

Speriamo che questo articolo vi abbia abilitato oEmbed nei widget di testo. Se avete domande o commenti, fatecelo sapere lasciando un commento qui sotto.

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 commentiLeave 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.