Keep Old Feed Addresses Working After Moving to WordPress
Redirects feed addresses used by Blogger, Ghost, Jekyll, Hugo and other platforms, such as /rss.xml or /feeds/posts/default, to your WordPress feed, so existing subscribers keep receiving posts.
Opens WPIDE on
Code
// Old feed addresses (from Blogger, Ghost, Jekyll, Squarespace ...) that should lead to your WordPress feed.
$wpide_old_feed_paths = array( '/rss.xml', '/feed.xml', '/atom.xml', '/index.xml', '/index.rdf', '/rss', '/feeds/posts/default' );
add_action( 'template_redirect', function () use ( $wpide_old_feed_paths ) {
if ( ! is_404() ) {
return;
}
$path = isset( $_SERVER['REQUEST_URI'] ) ? (string) wp_parse_url( wp_unslash( $_SERVER['REQUEST_URI'] ), PHP_URL_PATH ) : '';
$base = (string) wp_parse_url( home_url( '/' ), PHP_URL_PATH );
if ( '' === $path ) {
return;
}
// Path relative to the site, so subdirectory installs work too.
$relative = '/' . ltrim( substr( $path, strlen( untrailingslashit( $base ) ) ), '/' );
$relative = strtolower( untrailingslashit( $relative ) );
foreach ( $wpide_old_feed_paths as $old ) {
if ( strtolower( untrailingslashit( $old ) ) === $relative ) {
wp_safe_redirect( get_feed_link(), 301 );
exit;
}
}
} );
Notes
Only addresses that would otherwise be a 404 are redirected; add any other old feed paths to the list.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.