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

Come personalizzare completamente i feed RSS di WordPress

Nota editoriale: guadagniamo una commissione dai link dei partner su WPBeginner. Le commissioni non influenzano le opinioni o le valutazioni dei nostri redattori. Per saperne di più su Processo editoriale.

Volete aggiungere contenuti ai feed RSS di WordPress?

RSS è l’acronimo di “Really Simple Syndication” e i feed RSS di WordPress mostrano i contenuti più recenti. Tuttavia, per impostazione predefinita, non esiste alcuna opzione per personalizzare i contenuti per gli utenti dei feed RSS.

In questo articolo vi mostreremo come aggiungere facilmente contenuti e manipolare completamente i feed RSS di WordPress.

Adding custom content to your WordPress RSS feeds

Ecco una rapida panoramica degli aspetti che copriremo in questo articolo:

Aggiungere contenuti personalizzati ai feed RSS di WordPress (in modo semplice)

Il modo più semplice per aggiungere contenuti personalizzati del sito web ai feed RSS di WordPress è utilizzare il plugin All in One SEO. È il miglior plugin SEO per WordPress presente sul mercato e permette di ottimizzare facilmente la SEO del sito web.

La prima cosa da fare è installare e attivare il plugin All in One SEO. Per maggiori dettagli, consultate la nostra guida passo-passo su come installare un plugin di WordPress.

Dopo l’attivazione, verrà richiesto di configurare il plugin. È sufficiente seguire le istruzioni sullo schermo oppure selezionare la nostra guida su come configurare All in One SEO.

Successivamente, è necessario visitare la pagina All in One SEO ” Impostazioni generali e passare alla scheda “Contenuto RSS”.

Adding custom content to your WordPress RSS feed using All in One SEO

Da qui è possibile aggiungere il contenuto da visualizzare prima e dopo ogni elemento del feed RSS.

È possibile utilizzare gli smart tag per aggiungere colleghi e altri metadati ai contenuti personalizzati.

Adding before and after content for each post in your RSS feed

È inoltre possibile utilizzare l’HTML di base per formattare i contenuti personalizzati nel modo desiderato.

Una volta soddisfatti delle modifiche, non dimenticate di fare clic sul pulsante Salva modifiche.

All in One SEO aggiunge ora il contenuto personalizzato a ciascun elemento del feed RSS.

Aggiunta di contenuti al feed RSS di WordPress con il codice

Il primo metodo citato è il più semplice per aggiungere contenuti personalizzati ai feed RSS di WordPress. Tuttavia, aggiunge contenuti a tutti gli elementi del feed di WordPress.

E se si volessero aggiungere contenuti a articoli specifici, articoli di categorie selezionate o visualizzare metadati personalizzati nel feed RSS?

I prossimi passi vi aiuteranno ad aggiungere in modo flessibile contenuti al vostro feed RSS utilizzando snippet di codice personalizzati. Questa operazione non è consigliata ai principianti.

È possibile aggiungere questi frammenti di codice direttamente al file functions.php del tema. Tuttavia, vi consigliamo di utilizzare il plugin WPCode, perché è il modo più semplice per aggiungere codice personalizzato a WordPress senza rompere il vostro sito web.

Include anche diversi snippet RSS nella sua libreria che possono essere attivati facendo pochi clic.

È sufficiente installare e attivare il plugin gratuito WPCode seguendo le istruzioni della nostra guida su come installare un plugin per WordPress.

Proviamo alcuni esempi di aggiunta manuale di contenuti personalizzati nei feed RSS di WordPress.

1. Aggiungere i dati di un campo personalizzato al feed RSS di WordPress

Icampi personalizzati consentono di aggiungere metadati supplementari agli articoli e alle pagine di WordPress. Tuttavia, questi metadati non sono inclusi nei feed RSS in modo predefinito.

Adding custom fields in WordPress

Ecco uno snippet che potete utilizzare per recuperare e visualizzare i dati dei campi personalizzati nel feed RSS di WordPress:

function wpb_rsstutorial_customfield($content) {
global $wp_query;
$postid = $wp_query->post->ID;
$custom_metadata = get_post_meta($postid, 'my_custom_field', true);
if(is_feed()) {
if($custom_metadata !== '') {
// Display custom field data below content
$content = $content."<br /><br /><div>".$custom_metadata."</div>
";
}
else {
$content = $content;
}
}
return $content;
}
add_filter('the_excerpt_rss', 'wpb_rsstutorial_customfield');
add_filter('the_content', 'wpb_rsstutorial_customfield');

Questo codice seleziona innanzitutto se il campo personalizzato contiene dati e se il feed RSS personalizzato è visualizzato. Dopodiché, aggiunge semplicemente la variabile globale content e i dati del campo personalizzato sotto il contenuto.

2. Aggiunta di testo aggiuntivo ai titoli degli articoli in RSS

Volete visualizzare del testo aggiuntivo al titolo di alcuni articoli nel vostro feed RSS? Forse volete distinguere tra gli articoli normali e gli articoli degli ospiti o sponsorizzati.

Ecco come aggiungere contenuti personalizzati ai titoli degli articoli nel feed RSS.

Esempio 1: Aggiunta di dati da campi personalizzati al titolo di un articolo del feed RSS

Per prima cosa, è necessario salvare il contenuto che si desidera visualizzare come campo personalizzato. Ad esempio, è possibile aggiungere campi personalizzati guest_post o sponsored_post.

Dopodiché, potete aggiungere il seguente codice al vostro sito web:

function wpb_rsstutorial_addtitle($content) {
global $wp_query;
$postid = $wp_query->post->ID;
$gpost = get_post_meta($postid, 'guest_post', true);
$spost = get_post_meta($postid, 'sponsored_post', true);
 
if($gpost !== '') {
$content = 'Guest Post: '.$content;
}
elseif ($spost !== ''){
$content = 'Sponsored Post: '.$content;
}
else {
$content = $content;
}
return $content;
}
add_filter('the_title_rss', 'wpb_rsstutorial_addtitle');

Questo codice cerca semplicemente i campi personalizzati. Se non sono vuoti, aggiunge il valore del campo personalizzato al titolo dell’articolo nel feed RSS.

Esempio 2: Aggiunta del nome della categoria al titolo dell’articolo nel feed RSS

In questo esempio, visualizzeremo il nome della categoria nel titolo dell’articolo.

È sufficiente aggiungere il seguente codice al sito web:

function wpb_rsstutorial_titlecat($content) {
$postcat = "";
foreach((get_the_category()) as $cat) {
$postcat .= ' ('.$cat->cat_name . ')';
}
$content = $content.$postcat;
return $content;
}
add_filter('the_title_rss', 'wpb_rsstutorial_titlecat');

Ora, nel feed RSS vengono mostrate le categorie insieme ai titoli degli articoli. Ad esempio, “In alto i nuovi ristoranti della Bay Area (Notizie) (Viaggi)”, dove Notizie e Viaggi sono categorie.

3. Aggiunta di contenuti personalizzati agli articoli con tag o categorie specifiche

Supponiamo ora di voler aggiungere contenuti personalizzati, ma solo per articoli archiviati sotto tag o categorie specifiche.

Il codice seguente vi aiuterà ad aggiungere facilmente contenuti agli articoli archiviati in categorie e tag specifici:

function wpb_rsstutorial_taxonomies($content) {
 
if( is_feed() ){
 
// Check for posts filed under these categories
if ( has_term( array( 'travel', 'news' ), 'category' ) ) {
 
$content = $content."<br /><br />For special offers please visit our website"; 
 
}
}
return $content;
}
add_filter('the_excerpt_rss', 'wpb_rsstutorial_taxonomies');
add_filter('the_content', 'wpb_rsstutorial_taxonomies');

È possibile modificare questo codice per indirizzare i tagga e le tassonomie personalizzate.

Ecco un esempio di targeting di tag specifici:

function wpb_rsstutorial_taxonomies($content) {
 
if( is_feed() ){
 
// Check for posts filed under these categories
if ( has_term( array( 'holidays', 'blackfriday' ), 'post_tag' ) ) {
 
$content = $content."<br /><br />For special offers please visit our website"; 
 
}
}
return $content;
}
add_filter('the_excerpt_rss', 'wpb_rsstutorial_taxonomies');
add_filter('the_content', 'wpb_rsstutorial_taxonomies');

Di default, il feed RSS di WordPress non mostra immagini in evidenza per gli articoli. È possibile aggiungerle facilmente utilizzando uno snippet di codice incluso nella libreria di WPCode.

È sufficiente navigare in Code Snippets ” + Add Snippet e cercare nella libreria ‘rss’.

Si può quindi passare del mouse sullo snippet denominato “Aggiungi immagini in evidenza ai feed RSS” e fare clic sul pulsante “Usa snippet”.

WPCode Includes a Snippet to Add Featured Images to Your RSS Feed

A questo punto, è sufficiente spostare la levetta “Attivo” sulla posizione On e fare clic sul pulsante “Aggiorna”.

Le immagini in evidenza sono state aggiunte ai feed RSS.

Toggle the Active Switch On

È anche possibile aggiungere manualmente immagini in evidenza al feed RSS.

Questo è il codice da utilizzare:

function wpb_rsstutorial_featuredimage($content) {
global $post;
if(has_post_thumbnail($post->ID)) {
$content = '<p>' . get_the_post_thumbnail($post->ID) .
'</p>' . get_the_content();
}
return $content;
}
add_filter('the_excerpt_rss', 'wpb_rsstutorial_featuredimage');
add_filter('the_content_feed', 'wpb_rsstutorial_featuredimage');

Questo codice seleziona semplicemente se un articolo ha un’immagine in evidenza e la visualizza insieme al resto del contenuto dell’articolo.

Risorse bonus sulla personalizzazione dei feed RSS di WordPress

I feed RSS possono essere uno strumento utile per attirare più utenti e mantenere gli abbonati esistenti. Ecco alcune risorse che vi aiuteranno a ottimizzare ulteriormente i feed di WordPress:

Speriamo che questo articolo vi abbia aiutato a capire come aggiungere contenuti ai feed RSS di WordPress. Potreste anche voler consultare la nostra guida su come add-on al vostro blog WordPress o la nostra scelta di esperti sui migliori plugin per directory aziendali WordPress.

Se questo articolo vi è piaciuto, iscrivetevi al nostro canale YouTube per le esercitazioni video su WordPress. Potete trovarci anche su Twitter e Facebook.

Divulgazione: I nostri contenuti sono sostenuti dai lettori. Ciò significa che se cliccate su alcuni dei nostri link, potremmo guadagnare una commissione. Vedi come WPBeginner è finanziato , perché è importante e come puoi sostenerci. Ecco il nostro processo editoriale .

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.

Il kit di strumenti WordPress definitivo

Ottenete l'accesso gratuito al nostro kit di strumenti - una raccolta di prodotti e risorse relative a WordPress che ogni professionista dovrebbe avere!

Reader Interactions

39 commentiLascia una risposta

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Roberto Diaz says

    Hi guys, I am trying to add the featured image by default to RSS posts and I have 2 questions:

    1. Where exactly do you add the code you mention?
    2. In your code I see “function wpb_rsstutorial” are we supposed to replace this or any other part of the code with our own parameters?

    Thank you for your help!

    • WPBeginner Support says

      If you check under our ‘Adding Content to WordPress RSS Feed using Code’ section we cover the different methods for adding the code from our guide.

      For the function names, those are not required to be changed unless you want to and if you change it you would want to ensure you change every instance of it with the original name to your new name.

      Admin

    • WPBeginner Support says

      We do not recommend adding content after every paragraph in your RSS feed at this time.

      Admin

  3. Macca Sherifi says

    On your RSS feed you’ve got a real simple “To leave a comment please visit [Post Title] on WPBeginner.”

    How do I replicate this? In your code that you’ve supplied, presumably I have to change “coolcustom”, but which one do I edit specifically?

  4. Lapan says

    Hi.
    If I have in post:
    [text1]Text one[text1]
    [text2]Text two[text2]

    How do I return text2 shortcode in rss only?

  5. Gretchen Louise says

    I’m trying to use the third option to add the Digg Digg plugin’s buttons to the bottom of my RSS feeds. Any suggestions on editing the content to incorporate PHP rather than just text?

  6. brandy says

    I am trying to use this to implement CSS disclosure buttons in my feed, but I *cannot* figure out how to get it into the description. I have code of what I tried (2 different functions for the excerpt & the post). i hate how the buttons show up in the excerpt and i don’t think it’s necessary. help? :)

  7. Matt says

    I really appreciate you sharing this information with us. I have implemented this on my site now…I always really liked how it looks in your “weekly” emails that I receive.

    I think that it looks very professional and of course it is gonna help fight back against those content scrapers (thieves).

    Again, well written code, and very useful advice. Thank you!

  8. Adam says

    Great info! One question…  on #1 Add a Custom Field to your WordPress RSS Footer, for some reason the content/custom field is displayed twice. Any idea why?

  9. rahul says

    I have problem that in my site if someone fills a contact us form then his all personal info is displayed in rss feed and any user can see it
    plz help !!!!!
     

  10. thehifly says

    I actually got it now. Just edited the “$content = $content.”<br /><br /><div>”.$coolcustom.”</div>n”;” line. Perfect!

  11. thehifly says

    Adding the additional text works great but I’m trying to have the RSS to show only that custom field (for example the “coolcustom”) as the post’s description. Get rid of the actual text of the post. Is that possible?

  12. scot says

    Hi, I’m looking to add two fields to my ‘full’ rss feed. One which displays the author of the post and the other which displays a list of the taxomonies, if any, that the post is in. So let’s say the author is JohnR and the post is in the NFL, Raiders and Jets taxonomies, the RSS would have two additional fields:

    JohnR
    NFL, Raiders, Jets

    Can someone point me in the right direction to get this done?

    – Scot

  13. Agilworld says

    Thanks for sharing…

    Your tutorial is useful to me for verify the Technorati claim token! It worked nicely. I was looking for an effective way to verify it and found articles that discuss about that. But most of it, is not effective. And in the end, thought in my mind how add extra text in each footer post RSS feeds, Great! I found a smart way through your article, Thanks!!

  14. Juri says

    Hi,
    your code to add Custom Fields to RSS works great!!!! Thanks!
    I’m wondering if there is a way to edit the position and not to show the custom fields in the footer but above the title, or under the title, or etc… Is there a chance to add the tag “style” and so use some css?
    Thank you very much

  15. Juri says

    Add a Custom Field to your WordPress RSS Footer:
    THANKS Your code works perfectly. I have a question: How can I edit the position to show custom field up before the title or just after the title?
    I tried to edit the code here:
    $content = $content.””.$coolcustom.”
    “;
    I can remove the br tags and it works but where can I add style and css?

    Thanks for your great help

    • Editorial Staff says

      You would have to use inline styling for the RSS to work on all different readers. To add it before, you will add it like $coolcustom.$content and then add div tags using quotation where you like…

      Admin

  16. Robert Simpson says

    Hi,

    I’m trying to find a way to use a custom field to EXCLUDE a post from the RSS feed.

    Any ideas?

    Cheers,
    Robert

  17. Zach says

    Hey, thanks for the tutorial. It worked perfectly. Had a quick question though – after I get the extra content to load into the RSS Feed (for example if I’m viewing it in Safari), when I actually embed the RSS Feed on a website, that extra info goes away. Do you have any idea why that would happen? It’s been about 4 days as well – and I’ve tried clearing my cache several times. Thanks!

  18. kiki says

    Thanks for this so far! I haven’t been able to find much on adding custom fields to the RSS feed until now.

    Would it be difficult to add multiple custom fields with the code from section 1? I have an event listing website with custom fields for each post I want to display in the RSS, i.e. “Venue,” “Event Date,” “Address,” et al.

      • Kiki says

        Sorry, I’m a bit of a novice, but what would the code look like to get the multiple custom fields. I’ve tried playing with a few configurations of the code so far but it keeps resulting in errors. One field is working great though!

    • Editorial Staff says

      Ajay but does your plugin allows one to add custom fields in the RSS Text? Because it just seems like that it has the exact same functionality that Joost’s RSS Footer Plugin has which is not what this article is showing. What if you need to display different FTC texts for each post, then plugins like yours and RSS Footer would fail because they show the same text on each post. With this, one can set different ways: For example, if custom field this: Display that otherwise display the default copyright or something like that.

      Admin

  19. Oscar says

    This is great, it should help out a lot when trying to do quick little customizations. Little bite-sized tips like this are very helpful. I’ve seen people put some of the social media icons at the bottom too, to add to digg, and su and stuff.

Lascia una risposta

Grazie per aver scelto di lasciare un commento. Tenga presente che tutti i commenti sono moderati in base alle nostre politica dei commenti e il suo indirizzo e-mail NON sarà pubblicato. Si prega di NON utilizzare parole chiave nel campo del nome. Avremo una conversazione personale e significativa.