WordPress comes with built-in default RSS feeds. You can modify the default feeds by adding custom content to your RSS feeds, or even adding a post thumbnail to your RSS feeds. The default RSS and Atom feeds are sufficient for most users, but you may want to create a custom RSS feed to deliver a specific type of content. In this article, we will show you how to create custom RSS feeds in WordPress.
Please note that this tutorial is not intended for beginner level WordPress users. If you are a beginner, and still want to give it a try, do it on a local install.
As always, you should create a full backup of your WordPress website before making any major changes to a live website.
With that said, let's get started with your first custom RSS feed in WordPress.
Suppose you want to create a new RSS feed that displays only the following information:
The first thing you need to do is create the new RSS feed in your theme funciones.php
file or in a site-specific plugin:
add_action ('init', 'customRSS'); función customRSS () add_feed ('feedname', 'customRSSFunc');
The above code activates the customRSS
Function, which adds the feed. The add_feed function has two arguments, feedname and a callback function. The feedname will create your new feed URL yourdomain.com/feed/feedname
and the callback function will be called to actually create the feed. Make a note of the feed name, as you'll need it later.
Once you've initialized the font, you'll need to create the callback function to produce the required font, using the following code in your theme funciones.php
file or in a site-specific plugin:
función customRSSFunc () get_template_part ('rss', 'feedname');
The code above is using the get_template_part
function to link to a separate template file, however you can also place the RSS code directly in the function. By using get_template_part
, We can keep the functionality separate from the design. the get_template_part
The function has two arguments, slug and name, which will look for a template file with the name in the following format, starting with the file at the top (if it doesn't find the first, it will move to the second, and soon):
wp-content / themes / child / rss-feedname.php
wp-content / themes / parent / rss-feedname.php
wp-content / themes / child / rss.php
wp-content / themes / parent / rss.php
For the purposes of this tutorial, it's best to set the slug to the type of feed you're creating (in this case:rss), and the name to the feed name set above.
Once you've told WordPress to look for the feed template, you'll need to create it. The following code will produce the font layout with the information we listed above. Save this file in your theme folder as the template file slug-name.php set to get_template_part
function.
- Alimentar
This template code will generate an RSS feed following the design above. the recuento de entradas
The variable allows you to control the number of posts that will be displayed in your feed. The template can be modified as needed to display the information you need (eg post images, comments, etc.).
the the_excerpt_rss
The function will display the excerpt of each post, and for posts that don't have excerpts, it will display the first 120 words of the post content.
Finally, to display your feed, you will first need to clean up your WordPress rewrite rules. The easiest way to do this is to log in to your WordPress admin and click on Settings -> Permalinks . Once here, simply click Save Changes , which will clear the rewrite rules.
You can now access your new feed at yourdomain.com/feed/feedname
, where feedname was the feedname you gave in the add_feed
work sooner.
The W3C offers a feed validation service, which allows you to validate the resulting feed.
add_feed
functionadd_feed
function.global $ wp_rewrite; $ wp_rewrite-> flush_rules ();
funciones.php
File, to update the language option..function rssLanguage () update_option ('rss_language', 'en'); add_action ('admin_init', 'rssLanguage');
We hope this article has helped you create your own custom RSS feeds in WordPress. Let us know how and why you are going to use custom RSS feeds on your WordPress site by leaving a comment below.