Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

Start with WordPress’s built-in post-type feed rewrite. In register_post_type(), enable rewrite.feeds (usually alongside has_archive), refresh permalinks, and test the resulting archive feed. Use an explicit custom feed route only when you need a nonstandard URL or feed-specific behavior; that approach also requires careful query-variable registration and query scoping.

1. Check whether the post type already has a feed

Find the code that registers the custom post type. WordPress builds feed permastructures from the rewrite arguments passed to register_post_type(). The documented default for rewrite.feeds follows has_archive, so an archive-enabled post type may already have a feed route. See the register_post_type() reference.

The exact URL is determined by the post type key, archive slug, permalink structure and other rewrite settings; do not assume one universal path.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Example registration

add_action( 'init', function () {
    register_post_type( 'book', array(
        'public'      => true,
        'has_archive' => true,
        'rewrite'     => array(
            'slug'  => 'books',
            'feeds' => true,
        ),
    ) );
} );

Replace book with the site’s actual post-type key and books with the desired archive slug. After this registration is active, try the feed associated with that post-type archive before adding custom routing.

2. Choose the simplest route that meets the requirement

Approach Use it when Trade-offs
Built-in post-type feed rewrite The standard archive-based feed URL is acceptable and rewrite.feeds is enabled. Fewer moving parts; URL follows the registered archive and permalink structure.
Explicit custom feed route You need a custom slug, special request handling or feed-specific output. More control, but you must register the route, allow any custom query variable, scope the query and refresh rewrite rules.

3. Add a custom feed route only when necessary

WordPress’s feed APIs can register a named feed, while rewrite rules can map a custom URL to that feed. The WordPress feed customization documentation shows the general pattern for distinguishing a feed and routing it to a post type.

Register a named feed

add_action( 'init', function () {
    add_feed( 'books', function () {
        // Render the feed with the site's chosen feed template.
        // The request must resolve to post_type=book.
    } );
} );

This is an outline, not a universal drop-in implementation. The callback must output valid RSS or Atom XML using the site’s feed template, and the route must consistently identify the intended post type. If a rewrite rule introduces a query variable of its own, whitelist that variable with the query_vars filter; WordPress documents this filter as the mechanism for allowing public variables required by custom rewrite rules.

For example, a custom variable can be allowed as follows (use the same variable name in the rewrite rule and request handling):

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
add_filter( 'query_vars', function ( $vars ) {
    $vars[] = 'book_feed';
    return $vars;
} );

See the query_vars hook reference before choosing a variable name or rewrite shape.

4. Limit the feed query to the intended post type

If the custom route needs to alter the main feed query, use pre_get_posts and guard every condition. The hook runs before a query is executed; careless changes can affect unrelated feeds, secondary queries or administrative requests. The official guidance is in the pre_get_posts reference.

add_action( 'pre_get_posts', function ( $query ) {
    if ( is_admin() || ! $query->is_main_query() || ! $query->is_feed() ) {
        return;
    }

    if ( 'books' === $query->get( 'feed' ) ) {
        $query->set( 'post_type', 'book' );
    }
} );

Treat the condition on 'books' as an example. The feed value and route test must match the way the custom feed was registered. Use methods on the passed $query object for query conditions, and avoid changing queries that are not the target feed.

5. Refresh rewrite rules safely

New post-type or custom-feed routes may return 404 until rewrite rules are refreshed. The normal manual method is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. In WordPress admin, open Settings → Permalinks.
  2. Click Save Changes without changing the structure.
  3. Open the actual feed URL generated by the site and verify the response.

For a plugin-registered route, flush rewrite rules on plugin activation or deactivation rather than on every request. The register_post_type() documentation describes activation and permalink-refresh considerations.

6. Verify the result

  • Request the feed URL in a browser or feed reader.
  • Confirm the response is RSS or Atom XML, not a 404 page or ordinary HTML.
  • Check that every entry belongs to the intended custom post type.
  • Test pagination or older entries if the feed is expected to contain more than one page of results.
  • Test while logged out, because public-feed behavior can differ from authenticated requests.

7. Keep content registration independent of the theme

Place the custom post-type registration, and usually its feed-routing code, in a plugin or must-use plugin when the content should remain available after a theme change. WordPress’s Working with Custom Post Types guidance recommends this arrangement so the post type does not disappear from the admin when the theme is replaced.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common failure points

The feed URL returns 404

Confirm that the registration runs on init, the post type is public, the rewrite settings are active, and permalinks have been saved after the route was introduced.

The feed contains ordinary posts

Inspect the main-query guard and the route condition in pre_get_posts. Set post_type only for the intended feed; do not apply the change to every feed request.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A custom route variable is ignored

Add the variable through query_vars and make sure the rewrite rule, feed registration and query test use exactly the same name.

The post type vanishes after a theme switch

Move registration into a plugin or must-use plugin, then refresh permalinks and retest the feed.

Practical decision

Use the built-in feed rewrite when the standard archive-derived URL is sufficient. Build a named custom feed only for a deliberate URL or output requirement, and then treat route registration, allowed query variables, narrowly scoped query changes and rewrite refresh as one implementation package. Because URL behavior depends on the site’s WordPress version and registration code, validate the final route on the target installation.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.