Trending September 2023 # How To Create Custom Rss Feeds In WordPress # Suggested October 2023 # Top 16 Popular | Speedmintonvn.com

Trending September 2023 # How To Create Custom Rss Feeds In WordPress # Suggested October 2023 # Top 16 Popular

You are reading the article How To Create Custom Rss Feeds In WordPress updated in September 2023 on the website Speedmintonvn.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested October 2023 How To Create Custom Rss Feeds In WordPress

What’s better than an RSS Feed? Custom RSS Feeds of course! A lot of people have predicted the death of this sharing technology for eons now, but it is still going strong.

Statistics show that over 2000 of the world’s top 10,000 websites publish RSS feeds religiously. Feedly, a popular RSS feed aggregation service, grew its subscriber base by 900% in two years and revenue by more than 400%.

You might be interested in giving your visitors a customized user experience beyond your default WordPress RSS feed. Let’s explore how to customize your feeds to suit your website and audience.

Back Up Your Website

You’ll be going to your website’s back end, so back up your site. If anything breaks, you’ll still have your website, content, and settings intact. Don’t neglect this step, no matter what!

Also, we will be creating a new template file for your WordPress theme, so you might want to switch to/create a child theme so as not to mess up your existing theme.

Creating Custom RSS Feed in WordPress

To get started, we will be working with the “functions.php” file in your theme folder. Open it and paste the code below:

/* This code initializes the custom RSS Feeds for your website*/

add_action

(

'init'

,

'MyCustomRSS'

)

;

function

MyCustomRSS

(

)

{

add_feed

(

'mycustomfeedname'

,

'MyCustomFeedCallback'

)

;

}

/* This code seeks the template for your RSS feed */

function

MyCustomFeedCallback

(

)

{

get_template_part

(

'rss'

,

'mycustomfeedname'

)

;

// need to be in small case.

Note: Your custom RSS feed’s name can only be in small letters.

Create a Custom RSS Feeds Template

The custom RSS feed’s template is the information your feed will need to serve your feed. Think of it as an HTML/CSS kind of feature for your feed. To do this, you have to create another file with a unique name. This name MUST follow the convention: “rss-mycustomfeedname.php.”

Save this file in your child theme folder. Now open this file and paste the following code:

<?php

/** * Template Name: Custom RSS Template - YourCustomFeedName */

$postCount

=

10

;

// The number of posts to show in the feed

$postType

=

'post'

;

// post type to display in the feed

$charset

=

get_option

(

'blog_charset'

)

;

<rss version="2.0"

<?php

// Reset Query

wp_reset_query

(

)

;

You can modify this file to show as many posts as you want. Use the $postCount variable to change the number of posts to display. The default is showing “Posts,” but you can change it to show a different post type by changing the $postType variable. The excerpts feature will also show excerpts for your posts. If your post doesn’t have excerpts it will show the first 120 words in the article.

Adding Functionality to the Custom RSS Feeds

Now that you have a functional template, you can add additional stuff to it.

Show Post Thumbnail in Feeds

If you want to include post thumbnails in your feed, copy and paste the following code to the bottom of your “functions.php” file.

If your post has a thumbnail image, this function will search for it and serve it together with your feed text. If it doesn’t have any image, then it does nothing.

/*This code adds thumbnail feature to your custom feed*/

add_action

(

'rss2_item'

,

'custom_thumbnail_tag'

)

;

function

custom_thumbnail_tag

(

)

{

global

$post

;

}

}

Set Feed Language

Sometimes you may need to declare the language for your custom feed for it to work.

Do this by using this code in your “functions.php” file:

function

myFeedLanguage

(

)

{

update_option

(

'rss_language'

,

'en'

)

;

}

add_action

(

'admin_init'

,

'myFeedLanguage'

)

;

This will configure your language to English. If you intend to change it to another language, then edit the en in the function code to your preferred language. Get a list of all language codes from this link.

Get Your Custom Feed Working Wrapping Up

A Custom RSS feed is a great way to serve your content to people who may not have enough connectivity to access your full website. It also helps new audiences discover you through RSS feed apps on Android and iOS. You should absolutely give it a try.

Image credit: United Colors of Feeds

Nicholas Godwin

Nicholas Godwin is a technology researcher who helps businesses tell profitable brand stories that their audiences love. He's worked on projects for Fortune 500 companies, global tech corporations and top consulting firms, from Bloomberg Beta, Accenture, PwC, and Deloitte to HP, Shell, and AT&T. You may follow his work on Twitter or simply say hello. His website is Tech Write Researcher.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Sign up for all newsletters.

By signing up, you agree to our Privacy Policy and European users agree to the data transfer policy. We will not share your data and you can unsubscribe at any time.

You're reading How To Create Custom Rss Feeds In WordPress

Update the detailed information about How To Create Custom Rss Feeds In WordPress on the Speedmintonvn.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!