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

Jak całkowicie dostosować własne kanały RSS WordPressa

Uwaga redakcyjna: Otrzymujemy prowizję z linków partnerskich na WPBeginner. Prowizje nie mają wpływu na opinie i oceny naszych redaktorów. Dowiedz się więcej o Proces redakcyjny.

Czy chcesz dodawać treści do swoich kanałów RSS WordPress?

RSS to skrót od „Really Simple Syndication”, a kanały RSS WordPressa pokazują twoją najnowszą treść. Jednak domyślnie nie ma opcji dostosowania tej treści dla twoich klientów kanału RSS.

W tym artykule pokażemy, jak łatwo dodawać treści i całkowicie manipulować twoimi kanałami RSS WordPress.

Adding custom content to your WordPress RSS feeds

Oto krótki przegląd rzeczy, które omówimy w tym artykule:

Dodawanie własnych treści do kanałów RSS WordPress (prosty sposób)

Najprostszym sposobem na dodanie własnej treści witryny internetowej do kanałów RSS WordPress jest użycie wtyczki All in One SEO. Jest to najlepsza wtyczka WordPress SEO na rynku i pozwala łatwo zoptymalizować SEO Twojej witryny internetowej.

Pierwszą rzeczą, którą musisz zrobić, to zainstalować i włączyć wtyczkę All in One SEO. Aby uzyskać więcej informacji, zapoznaj się z naszym przewodnikiem krok po kroku, jak zainstalować wtyczkę WordPress.

Po włączaniu zostaniesz poproszony o skonfigurowanie wtyczki. Wystarczy postępować zgodnie z instrukcjami wyświetlanymi na ekranie lub zapoznać się z naszym przewodnikiem na temat konfiguracji All in One SEO.

Następnie należy przejść na stronę All in One SEO ” Ustawienia ogólne i przełączyć się na kartę „Treści RSS”.

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

W tym miejscu można dodawać treści, które mają być wyświetlane przed i po każdym elemencie kanału RSS.

Za pomocą tagów inteligentnych można dodawać odnośniki i inne metadane do treści własnych.

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

Możesz także użyć podstawowego HTML, aby sformatować twoją własną treść w dowolny sposób.

Po wprowadzeniu zmian nie zapomnij kliknąć przycisku Zapisz zmiany.

All in One SEO doda teraz twoją własną treść do każdej pozycji kanału RSS.

Dodawanie treści do kanału RSS WordPress za pomocą kodu

Pierwsza z wyżej wymienionych metod jest najłatwiejszym sposobem na dodanie własnej treści do twojego kanału RSS WordPress. Dodaje ona jednak treść do wszystkich elementów na Twoim kanale WordPress.

Co jeśli chciałbyś dodać treść do konkretnych wpisów, wpisów w wybranych kategoriach lub wyświetlić własne metadane na kanale RSS?

Kilka następnych kroków pomoże ci w elastycznym dodawaniu treści do twojego kanału RSS za pomocą własnych fragmentów kodu. Nie jest to zalecane dla początkujących.

Możesz dodać te fragmenty kodu bezpośrednio do pliku functions.php twojego motywu. Zalecamy jednak użycie wtyczki WPCode, ponieważ jest to najłatwiejszy sposób na dodanie własnego konfiguratora do WordPressa bez uszkadzania twojej witryny internetowej WordPress.

Zawiera nawet kilka fragmentów kodu RSS w swojej bibliotece, które można włączać za pomocą kilku kliknięć.

Wystarczy zainstalować i włączać darmową wtyczkę WPCode, korzystając z instrukcji zawartych w naszym przewodniku na temat instalacji wtyczki WordPress.

Wypróbujmy kilka przykładów ręcznego dodawania własnych treści w kanałach RSS WordPress.

1. Dodawanie danych z własnego pola do kanału RSS WordPressa

Pola własne umożliwiają dodawanie dodatkowych metadanych do twoich wpisów i stron WordPress. Metadane te nie są jednak domyślnie dołączane do kanałów RSS.

Adding custom fields in WordPress

Oto fragment kodu, którego możesz użyć do pobierania i wyświetlania danych pól własnych na kanale RSS 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');

Ten kod najpierw sprawdza, czy pole niestandardowe zawiera dane i czy wyświetlany jest własny kanał RSS. Następnie po prostu dołącza zmienną globalną treści i dodaje dane pola niestandardowego poniżej treści.

2. Dodawanie dodatkowego tekstu do wpisów w RSS

Czy chcesz wyświetlać dodatkowy tekst do tytułu niektórych wpisów na Twoim kanale RSS? Być może chcesz odróżnić zwykłe artykuły od wpisów gościnnych lub sponsorowanych.

Oto jak dodać własną treść do tytułów wpisów na kanale RSS.

Przykład 1: Dodawanie danych z pól własnych do tytułu wpisu w kanale RSS

Po pierwsze, będziesz chciał zapisać treść, którą chcesz wyświetlić jako pole własne. Możesz na przykład dodać pola własne guest_post lub sponsored_post.

Następnie możesz dodać następujący kod do twojej witryny internetowej:

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

Ten kod po prostu szuka pól własnych. Jeśli nie są puste, dołącza wartość pola własnego do tytułu wpisu na kanale RSS.

Przykład 2: Dodanie nazwy kategorii do tytułu wpisu w kanale RSS

W tym przykładzie wyświetlimy nazwę kategorii w tytule wpisu.

Wystarczy dodać poniższy kod do twojej witryny internetowej:

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

Teraz w kanale RSS będą wyświetlane kategorie wraz z tytułami wpisów. Na przykład, „Top New Restaurants in Bay Area (News) (Travel)”, gdzie News i Travel są kategoriami.

3. Dodawanie własnych treści do wpisów z określonymi tagami lub kategoriami

Załóżmy teraz, że chcesz dodać konfigurator treści, ale tylko dla wpisów umieszczonych w określonych tagach lub kategoriach.

Poniższy kod pomoże ci łatwo dodać treść do wpisów umieszczonych w określonych kategoriach i tagach:

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

Możesz zmodyfikować ten kod, aby kierować reklamy na tagi, a także na dowolne własne taksonomie.

Oto przykład kierowania na określone tagi:

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

Domyślnie Twój kanał RSS WordPress nie wyświetla wyróżniających się obrazków dla wpisów. Można je łatwo dodać za pomocą fragmentu kodu zawartego w bibliotece WPCode.

Wystarczy przejść do Code Snippets ” + Add Snippet, a następnie wyszukać w bibliotece „rss”.

Następnie można najechać kursorem na fragment kodu o nazwie „Add Featured Images to RSS Feeds” i kliknąć przycisk „Use Snippet”.

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

Teraz wystarczy przełączyć przełącznik „Włączanie” na pozycję „Włączone”, a następnie kliknąć przycisk „Aktualizuj”.

Wyróżniające się obrazki zostały dodane do Twoich kanałów RSS.

Toggle the Active Switch On

Możesz także dodać wyróżniające się obrazki do twojego kanału RSS ręcznie.

To jest kod, którego można użyć:

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

Ten kod po prostu sprawdza, czy wpis ma miniaturkę (obrazek wyróżniający) i wyświetla ją wraz z pozostałą treścią twojego wpisu.

Dodatkowe zasoby na temat dostosowywania kanałów RSS WordPressa

Kanały RSS mogą być pomocnym narzędziem w przyciąganiu większej liczby użytkowników i utrzymywaniu zaangażowania twoich obecnych subskrybentów. Oto kilka zasobów, które pomogą ci jeszcze bardziej zoptymalizować twoje kanały WordPress:

Mamy nadzieję, że ten artykuł pomógł Ci dowiedzieć się, jak dodawać treści na kanale RSS WordPress. Możesz również zapoznać się z naszym przewodnikiem na temat dodawania subskrypcji e-mail do twojego bloga WordPress lub z naszym wyborem ekspertów na temat najlepszych wtyczek do katalogów biznesowych WordPress.

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.

Ujawnienie: Nasze treści są wspierane przez czytelników. Oznacza to, że jeśli klikniesz na niektóre z naszych linków, możemy otrzymać prowizję. Zobacz jak WPBeginner jest finansowany, dlaczego to ma znaczenie i jak możesz nas wspierać. Oto nasz proces redakcyjny.

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.

Najlepszy zestaw narzędzi WordPress

Uzyskaj BEZPŁATNY dostęp do naszego zestawu narzędzi - zbiór produktów i zasobów związanych z WordPressem, które każdy profesjonalista powinien mieć!

Reader Interactions

39 komentarzyZostaw odpowiedź

  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.

      Administrator

    • WPBeginner Support says

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

      Administrator

  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…

      Administrator

  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.

      Administrator

  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.

Zostaw odpowiedź

Dziękujemy za pozostawienie komentarza. Pamiętaj, że wszystkie komentarze są moderowane zgodnie z naszymi polityka komentarzy, a Twój adres e-mail NIE zostanie opublikowany. NIE używaj słów kluczowych w polu nazwy. Przeprowadźmy osobistą i konstruktywną rozmowę.