Saturday, 27 May 2023

How to Make Separate RSS Feeds for Each Category in WordPress

Do you want to make a separate RSS feed for each category in WordPress?

Categories allow you to easily sort your content into major sections. Adding category RSS feeds can help your users subscribe to specific areas of your website that interest them.

In this article, we will show you how to easily make a separate RSS feed for each category in WordPress. We will also talk about how you can use these feeds effectively to grow your website.

How to make separate RSS feeds for each category in WordPress

How to Find RSS Feeds for Different Categories in WordPress

Categories and tags are two of the main default taxonomies in WordPress. They allow you to easily sort and organize your content into different subjects and topics.

By default, each category on your WordPress website has its own RSS feed. You can locate this RSS feed by simply adding ‘feed’ at the end of the category page URL.

For instance, if you have a category called ‘News’ with a URL like this:

https://ift.tt/JN6Amxa

Then its RSS feed would be located at the following URL:

https://ift.tt/yOjlCYN

Tip: You can find your category URL by visiting the Posts » Categories page and clicking on the ‘View’ link under a category.

View Category URL by clicking on the View link

Now that you have located the RSS feed URLs for your categories, let’s look at some of the ways that you can share them with visitors on your WordPress website.

If you want to add links to your category RSS feeds using the default WordPress settings, then this method is for you.

First, you will need to open up a page or post where you want to add the RSS feed links in the block editor.

Once you are there, you can type the name of all the categories on your website in a List block.

After that, simply click the ‘Link’ icon in the block toolbar to open up the link prompt.

Click the Link icon in the block toolbar

Here, you can type the URL for your category RSS feed.

You will need to repeat this process for each category RSS feed on your website by linking to it on the related name within the List block.

Add category RSS feed links

Once you are done, don’t forget to click the ‘Publish’ or ‘Update’ button to save your changes.

You have now manually created a list of links to all your category RSS feeds. Now, you can visit your website to see these RSS feed links in action.

Category RSS feed preview

However, keep in mind that if you want to add, delete, or merge categories in the future, then you will have to manually update this list again.

Method 2: Add Links for Category RSS Feeds Using WPCode (Recommended)

If you want to create a list of category RSS feed links that are automatically updated every time you make changes, then this method is for you.

To add URLs to the category RSS feed, we will need to add custom code to your website theme’s functions.php file. However, even the smallest error in the code can break your site, making it inaccessible.

We recommend always using WPCode when adding custom code to your website. It is the best WordPress code snippet plugin that makes it safe and easy to add custom code without manually editing your functions.php file.

First, you need to install and activate the WPCode plugin. For more instructions, you may want to see our guide on how to install a WordPress plugin.

Note: You can also use the free WPCode plugin for this tutorial. However, upgrading to the pro WPCode plugin will give you access to a cloud library of code snippets, smart conditional logic, and more.

Upon activation, head over to the Code Snippets » + Add Snippet page from the WordPress admin sidebar.

Next, click on the ‘Use Snippet’ button under the ‘Add Your Custom Code (New Snippet)’ option.

Add new snippet

This will take you to the ‘Create Custom Snippet’ page, where you can start by typing a name for your code snippet.

This name is only for your identification and won’t be used on the website’s front end.

Next, you need to select ‘PHP Snippet’ as the code type from the dropdown menu on the right corner of the screen.

Choose PHP Snippet as code type for category RSS feed

After that, copy and paste the following code into the ‘Code Preview’ box.

function wpbeginner_cat_feed_list() {
        $string = '<ul>';
        $string .= wp_list_categories( array(
                'orderby'    => 'name',
                'show_count' => true,
                'feed_image' => '/path/to/feed-image.png',
                'echo' => false,
        ) );
        $string .= '</ul>';

        return $string;
}

add_shortcode( 'wpb-cat-feeds', 'wpbeginner_cat_feed_list' );

Once you have done that, you can now also choose an icon image that will be displayed next to your category RSS feed links.

To do this, simply replace the /path/to/feed-image.png line in the code with the URL of your preferred icon image for the feed links.

Paste the code for adding links for category RSS feeds

Keep in mind that the icon image will first need to be uploaded to your WordPress media library.

Once it’s uploaded, you can get its URL by visiting the Media » Library page from the admin sidebar and clicking on the icon image to view its attachment details.

Copy image link from the media library

After adding the URL for the icon image to the code, scroll down to the ‘Insertion’ section.

From here, select the ‘Auto Insert’ method so that the code will be executed automatically on the website page where you add a shortcode.

Note: Keep in mind that even after choosing the ‘Auto Insert’ mode, you will need to add a [wpb-cat-feeds] shortcode to the page where you want to list categories RSS feeds. This shortcode is not the WPCode ‘Shortcode’ feature, but a part of the code snippet itself.

Choose an insertion method

Next, scroll back to the top and toggle the ‘Inactive’ switch to ‘Active’.

Finally, click the ‘Save Snippet’ button to store your settings.

Save the code snippet for adding RSS feed links to categories

After that, you need to open up the page or post where you want to add the category RSS feed links in your WordPress block editor.

From here, click the ‘Add Block’ (+) button at the top left corner of the screen and locate the ‘Shortcode’ block.

Upon adding the block, simply copy and paste the following shortcode into it.

[wpb-cat-feeds]

Add shortcode

Finally, click the ‘Update’ or ‘Publish’ button to save your changes.

Now visit your website to check the category RSS feed links in action.

Preview for category RSS feeds

Method 3: Display RSS Feed Subscription Option on the Category Pages

If you want to add a Subscribe link at the top of all your category pages, then you can use this method.

To do this, you will need to add custom code to your WordPress category.php or archive.php theme template.

However, it can be risky, and the smallest error can break your website.

This is why we recommend using WPCode instead. It is the easiest and safest way to add custom code to your WordPress website.

First, you need to install and activate the WPCode plugin. For more instructions, please see our step-by-step guide on how to install a WordPress plugin.

Upon activation, visit the Code Snippets » + Add Snippet page from the WordPress admin sidebar.

Next, head over to the ‘Add Your Custom Code (New Snippet)’ option and click the ‘Use Snippet’ button under it.

Add new snippet

Once you are taken to the ‘Create Custom Snippet’ page, start by typing a name for your code snippet.

It can be anything you like and is only for your identification purposes.

After that, select ‘PHP Snippet’ as the code type from the dropdown menu on the right.

Choose PHP code type for code snippet to add subscription links to category pages

Next, simply copy and paste the following code into the ‘Code Preview’ box.

<?php
if ( is_category() ) {
$category = get_category( get_query_var('cat') );
if ( ! empty( $category ) )
echo '<div class="category-feed"><p><a href="' . get_category_feed_link( $category->cat_ID ) . '" title="Subscribe to this category" rel="nofollow">Subscribe</a></p></div>';
}
?>
Paste the code snippet for adding subscription link

Upon adding the code, scroll down to the ‘Insertion’ section and choose the ‘Auto Insert’ method.

This way, the code will automatically be executed on your website.

Choose an insertion method

Next, you have to open up the ‘Location’ dropdown menu and switch to the ‘Page-Specific’ tab from the column on the left.

After that, select the ‘Insert Before Excerpt’ option as the snippet location.

Choose snippet location as Insert before excerpt

Once you have done that, scroll back to the top and toggle the ‘Inactive’ switch to ‘Active’.

Finally, click the ‘Save Snippet’ button to save your changes.

Save snippet for adding subscription link to category pages

Now, you can visit your website category page to view the Subscription link for the RSS feeds in action.

This is what it looked like on our demo website.

Preview for subscription link

How to Optimize Category RSS Feeds in WordPress

Category RSS feeds allow your users to subscribe only to content that interests them the most.

For instance, if you have a technology news blog, then your users can choose to subscribe only to news about the devices that they use.

However, a plain RSS feed isn’t readable without a feed reader, and most users aren’t using one to subscribe to their favorite websites.

Luckily, you can still use your category feeds to deliver content to your users anywhere they want.

For example, you can ask users to sign up for your email newsletter with the option to only get updates for specific content categories.

With email marketing services like Constant Contact or Brevo (formerly Sendinblue), you can easily set up an automated RSS-to-email newsletter for specific categories. You can see our guide on how to notify subscribers of new posts for step-by-step instructions.

Similarly, you can also allow users to get instant push notifications for each category using PushEngage. It is the best push notification service on the market that allows you to send messages directly to your users’ devices (desktops as well as mobile phones).

PushEngage allows you to set up automatic push notifications using RSS feeds. You simply need to enter your category RSS feed URL, and a push notification will go out whenever a new post is published in that category.

We hope this article helped you learn how to make separate RSS feeds for each category in WordPress. You may also want to see our easy tips to grow your blog traffic or read our comparison of the best live chat software for small businesses.

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.

The post How to Make Separate RSS Feeds for Each Category in WordPress first appeared on WPBeginner.



from WPBeginner https://ift.tt/9BejX7C
More links is https://mwktutor.com

No comments:

Post a Comment