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 Customize du helt och hållet dina WordPress RSS-flöden

RSS står för ”Really Simple Syndication”, och RSS-flöden är ett kraftfullt sätt att hålla din publik uppdaterad med ditt senaste innehåll. Men WordPress standardalternativ är ganska grundläggande och det finns inga alternativ för att anpassa dina RSS-flöden.

Som tur är kan vi visa dig hur du enkelt kan lägga till kod på din webbplats för att ge den en personlig touch, marknadsföra dina sociala medier eller ge dina RSS-prenumeranter en mer anpassad upplevelse.

Den här artikeln visar dig hur du går längre än grunderna och helt anpassar vad dina RSS-flödesprenumeranter ser. Du kommer att lära dig hur du lägger till anpassat innehåll, justerar formateringen och får dina RSS-flöden att arbeta hårdare för dig.

Adding custom content to your WordPress RSS feeds

Här är en snabb översikt över de saker som vi kommer att täcka i den här artikeln:

Add Custom Content till WordPress RSS-flöden (enkelt sätt)

Det enklaste sättet att add to custom website content till dina WordPress RSS-flöden är genom att använda All in One SEO plugin. Det är den bästa WordPress SEO plugin på marknaden och allow you att enkelt optimera din website SEO.

Det första du behöver göra är att installera och aktivera pluginet All in One SEO. För mer detaljer, se vår Step-by-Step guide om hur du installerar ett plugin för WordPress.

När du är aktiverad kommer du att uppmanas att konfigurera pluginet. Följ helt enkelt instruktionerna på skärmen eller kontrollera vår guide om hur du ställer in All in One SEO.

Efter det måste du besöka All in One SEO ” General Settings page och växla till fliken ’RSS Content’.

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

Härifrån kan du add to content som du vill ska visas före och efter varje objekt i RSS-flödet.

Du kan använda smarta taggar för att add to links och andra metadata till det customize content.

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

Du kan också använda grundläggande HTML för att formatera ditt customize content som du gillar.

När du är nöjd med ändringarna, glöm inte att clicka på knappen Save Changes.

All in One SEO kommer nu att lägga till ditt anpassade content till varje RSS-flöde objekt.

Lägga till innehåll till WordPress RSS-flöde med hjälp av kod

Den första metoden som nämns ovan är det enklaste sättet att add to custom content till dina WordPress RSS-flöden. Det lägger dock till content till alla objekt i your WordPress feed.

Tänk om du vill add to content till specifika posts, posts i utvalda kategorier eller visa custom metadata i ditt RSS-flöde?

De kommande stegen hjälper dig att flexibelt add to content till ditt RSS-flöde med hjälp av custom code snippets. Detta rekommenderas ej för Beginnare.

Du kan add dessa code snippets direkt till ditt temas functions.php-fil. Vi rekommenderar dock att du använder pluginet WPCode istället eftersom det är det enklaste sättet att add to customizer-kod till WordPress utan att förstöra din WordPress-webbplats.

Det innehåller även flera RSS-snippets i sitt bibliotek som kan aktiveras med några clicks.

Installera och aktivera WPCode gratis plugin med hjälp av instruktionerna i vår guide om hur man installerar ett WordPress plugin.

Låt oss prova några exempel på att lägga till custom content i WordPress RSS-flöden manuellt.

1. Add data från ett Customize-fält till ditt RSS-flöde i WordPress

Custom fields allow you to add extra metadata till dina WordPress posts och pages. Dessa metadata ingår dock inte i RSS-flöden som standard.

Adding custom fields in WordPress

Här är ett snippet du kan använda för att hämta och visa data från customize-fält i ditt WordPress RSS-flöde:

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');

Den här koden kontrollerar först om det anpassade fältet har data inuti och det anpassade RSS-flödet visas. Därefter lägger den helt enkelt till den globala variabeln content och adderar data från custom field under content.

2. Lägga till ytterligare text till rubriker i RSS

Vill du visa ytterligare text till rubriken på vissa poster i ditt RSS-flöde? Kanske vill du skilja mellan vanliga artiklar och gäst- eller sponsrade posts.

Så här kan du add to custom content till post titles i ditt RSS-flöde.

Exempel 1: Lägga till data från Customize-fält till RSS-flödets post Rubrik

Först vill du save det content du vill visa som ett custom field. Till exempel kan du add to guest_post eller sponsored_post custom fields.

Följaktligen kan du add to följande kod till din website:

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');

Den här koden letar helt enkelt efter de customize fälten. Om de inte är tomma, lägger den till värdet på det anpassade fältet till postens titel i ditt RSS-flöde.

Exempel 2: Lägga till Category Name till Post Rubrik i RSS-flöde

I det här exemplet kommer vi att displayed kategorinamnet i titeln på posten.

Add helt enkelt följande kod till din website:

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');

Nu kommer det att visa kategorier tillsammans med post rubriker i RSS-flödet. Till exempel ”Topp nya restauranger i Bay Area (Nyheter) (Resor)” där Nyheter och Resor är kategorier.

3. Add Custom Content till Posts med specifika Tags eller Categories

Låt oss nu anta att du vill lägga till custom content men bara för posts som arkiveras under specifika taggar eller kategorier.

Följer du denna kod kan du enkelt add to content till posts som är arkiverade under specifika kategorier och tags:

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');

Du kan ändra den här koden för att rikta in dig på taggar samt eventuella custom taxonomies.

Här är ett exempel på inriktning mot specifika taggar:

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');

Som standard visar ditt WordPress RSS-flöde inte featured images för inlägg. Du kan enkelt add to dem genom att använda ett code snippet som ingår i WPCodes bibliotek.

Navigera bara till Code Snippets ” + Add Snippet och sök sedan i biblioteket efter ’rss’.

Du kan sedan hovera över snippet som heter ”Add Featured Images to RSS Feeds” och klicka på knappen ”Use Snippet”.

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

Nu behöver du bara toggla ”Active” till positionen On och sedan clicka på knappen ”Update”.

Featured images har nu lagts till i dina RSS-flöden.

Toggle the Active Switch On

Du kan också lägga till featured images i ditt RSS-flöde manuellt.

Det här är koden du kan använda:

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');

Denna kod kontrollerar helt enkelt om ett inlägg har en thumbnail (featured image) och visar den tillsammans med resten av innehållet i ditt inlägg

Bonus Resources om att customize WordPress RSS-flöden

Vi hoppas att den här artikeln hjälpte dig att lära dig hur du lägger till innehåll i dina WordPress RSS-flöden. Du kanske också vill se några fler resurser som hjälper dig att ytterligare optimera dina WordPress-flöden:

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Avslöjande: Vårt innehåll stöds av våra läsare. Det innebär att om du klickar på några av våra länkar, kan vi tjäna en provision. Se hur WPBeginner finansieras, varför det är viktigt, och hur du kan stödja oss. Här är vår editoriala 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.

Den ultimata WordPress-verktygslådan

Få GRATIS tillgång till vår verktygslåda - en samling WordPress-relaterade produkter och resurser som varje professionell användare bör ha!

Reader Interactions

40 kommentarerLämna ett svar

  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. Dayo Olobayo says

    Thanks for outlining the different methods for adding custom content to RSS feeds. The option to use plugins or code snippets makes this accessible to a wider range of users. I had no idea that one can customize WordPress RSS feeds to this extent. This opens up a lot of possibilities for making my feed more engaging for my readers.

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

      Administratör

    • WPBeginner Support says

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

      Administratör

  4. 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?

  5. 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?

  6. 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?

  7. 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? :)

  8. 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!

  9. 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?

  10. 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 !!!!!
     

  11. thehifly says

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

  12. 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?

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

  14. 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!!

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

  16. 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…

      Administratör

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

  18. 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!

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

      Administratör

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

Lämna ett svar

Tack för att du väljer att lämna en kommentar. Tänk på att alla kommentarer modereras enligt våra policy för kommentarer, och din e-postadress kommer INTE att publiceras. Vänligen använd INTE nyckelord i namnfältet. Låt oss ha en personlig och meningsfull konversation.