trying to rewrite custom rss feed URL
-
I’ve created a new custom rss feed file (mycustomfeed.php) which is accessible at https://www.myblog.com/?feed=mycustomfeed. I’ve searched the forums for help trying to rewrite the URL, and found a link to the following bit of code from https://www.seodenver.com/custom-rss-feed-in-wordpress/
This piece of code will allow you to have any feed name, and dynamically “create” /customfeed.xml as well as a /feed/customfeed/ versions:
function custom_feed_rewrite($wp_rewrite) { $feed_rules = array( 'feed/(.+)' => 'index.php?feed=' . $wp_rewrite->preg_index(1), '(.+).xml' => 'index.php?feed='. $wp_rewrite->preg_index(1) ); $wp_rewrite->rules = $feed_rules + $wp_rewrite->rules; } add_filter('generate_rewrite_rules', 'custom_feed_rewrite');
So, I added the code to my functions.php file, but I’m not having any luck accessing the feed at https://www.myblog.com/mycustomfeed.xml or https://www.myblog.com/feed/mycustomfeed
Is there something incorrect in the bit of code that I copied, or am I missing something in the code that I need to customize? Or, perhaps, is there a better/easier way for me to do a rewrite so that I can access my custom feed at /mycustomfeed.xml and/or /feed/mycustomfeed ?
- The topic ‘trying to rewrite custom rss feed URL’ is closed to new replies.