1

I am in the process of creating a wordpress website, and I just have one issue left - RSS feeds.

Currently, the website has a .htaccess file blocking access to /category/* pages. It was part of a requirement that the site is not obviously Wordpress, and /category is a decent indicator of that.

Each category is fronted by a page, which displays the category content - so /category/news becomes /news.

However, RSS feeds always seem to point to /category/xxx/feed - is there a way to remove this /category/ part? So people could view the RSS feed at http://example.com/news/feed ?

I've tried fiddling around with the .htaccess file, but it's the one area of building a web application I'm not 100% sure on. Every search has returned with results of how to point a feed to Feedburner instead, which is not what I am looking to do at all.

6
  • "It was part of a requirement that the site is not obviously Wordpress" Hopefully the people who made this a requirement understand that it has absolutely zero benefit in improving security, if that was the point. Commented Jun 25, 2013 at 16:21
  • So /news is just a page, not category archive? Hm, I can't think of an easy way to move a category feed in such fashion on WP level... Commented Jun 25, 2013 at 21:28
  • @Milo: No, that was not the point. Commented Jun 26, 2013 at 8:47
  • @Rarst Me either :( Commented Jun 26, 2013 at 8:47
  • You do know that you can change the tag and category slug prefixes on the permalinks settings page, right? Commented Jun 28, 2013 at 16:08

3 Answers 3

1

After some thought - this can be achieved with some creative abuse of existing feeds:

  • easy part - redirect category feeds to page comment feeds
  • hard part - make page comment feeds think they are category feeds

Something like this:

Category_Feed_At_Page::on_load(); /** * Repurpose page feeds for category of same name feeds. */ class Category_Feed_At_Page { static function on_load() { add_action( 'pre_get_posts', array( __CLASS__, 'pre_get_posts' ) ); add_action( 'do_feed_rdf', array( __CLASS__, 'do_feed' ), 9 ); add_action( 'do_feed_rss', array( __CLASS__, 'do_feed' ), 9 ); add_action( 'do_feed_rss2', array( __CLASS__, 'do_feed' ), 9 ); add_action( 'do_feed_atom', array( __CLASS__, 'do_feed' ), 9 ); } /** * Change page's comment feed into category feed. * * @param WP_Query $query */ static function pre_get_posts( $query ) { if ( $query->is_main_query() && $query->is_page() && $query->is_feed() ) { $name = $query->get( 'pagename' ); require_once( ABSPATH . 'wp-admin/includes/taxonomy.php' ); if ( category_exists( $name ) ) { $category = get_category_by_slug( $name ); $query->set( 'category_name', $name ); $query->set( 'cat', $category->term_id ); $query->set( 'pagename', '' ); $query->is_page = false; $query->is_comment_feed = false; $query->is_category = true; $query->is_singular = false; remove_action( 'do_feed_rdf', array( __CLASS__, 'do_feed' ), 9 ); remove_action( 'do_feed_rss', array( __CLASS__, 'do_feed' ), 9 ); remove_action( 'do_feed_rss2', array( __CLASS__, 'do_feed' ), 9 ); remove_action( 'do_feed_atom', array( __CLASS__, 'do_feed' ), 9 ); remove_action( 'template_redirect', 'redirect_canonical' ); } } } /** * Redirect real category feed to page feed. */ static function do_feed() { if ( ! is_category() ) return; $name = get_query_var( 'category_name' ); $page = get_page_by_path( $name ); if ( ! empty( $page ) ) { wp_safe_redirect( get_post_comments_feed_link( $page->ID ) ); die; } } } 
1
  • Thanks Rarst, I will have a go with this and see how it works :) If it does the trick I will come back and mark this as answered. Cheers! Commented Jul 1, 2013 at 9:50
1

I found (in my opinion) the best and easiest way to do this, and thought I should leave it as an answer in case anybody stumbles upon this thread.

I downloaded and installed the WP No Category Base plugin and that did exactly what I needed.

Unfortunately, I never got around to trying the other answers (had to move on to a more urgent project), so I can't clarify if any of them work.


Updated Link: No Category Base (WPML)

2
0

You do know that you can change the tag and category slug prefixes on the permalinks settings page, right?

So if it bothers you to have the "category" in "/category/news", but accepts having "/cat/news", you can change that there.

1
  • Please do not use answers for discussion. You will be able to leave comments when you gain some reputation on site. (undeleted since made more answer-ish :) Commented Jun 28, 2013 at 16:11

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.