Using WordPress ‘post_type_archive_feed_link’ PHP filter

The post_type_archive_feed_link WordPress PHP filter allows you to modify the post type archive feed link for a given feed type.

Usage

add_filter( 'post_type_archive_feed_link', 'your_custom_function', 10, 2 );

function your_custom_function( $link, $feed ) {
    // your custom code here
    return $link;
}

Parameters

  • $link (string) – The post type archive feed link.
  • $feed (string) – Feed type. Possible values include ‘rss2’, ‘atom’.

More information

See WordPress Developer Resources: post_type_archive_feed_link

Examples

Change the post type archive feed link for the ‘rss2’ feed

This example modifies the post type archive feed link to a custom URL when the feed type is ‘rss2’.

add_filter( 'post_type_archive_feed_link', 'change_rss2_feed_link', 10, 2 );

function change_rss2_feed_link( $link, $feed ) {
    if ( 'rss2' === $feed ) {
        $link = 'https://example.com/custom-rss2-feed/';
    }
    return $link;
}

Add a custom parameter to the post type archive feed link

This example appends a custom parameter to the post type archive feed link.

add_filter( 'post_type_archive_feed_link', 'add_custom_parameter', 10, 2 );

function add_custom_parameter( $link, $feed ) {
    $link = add_query_arg( 'custom_param', 'value', $link );
    return $link;
}

Change the post type archive feed link for a custom post type

This example changes the post type archive feed link for a custom post type called ‘products’.

add_filter( 'post_type_archive_feed_link', 'change_products_feed_link', 10, 2 );

function change_products_feed_link( $link, $feed ) {
    if ( false !== strpos( $link, 'post_type=products' ) ) {
        $link = 'https://example.com/custom-products-feed/';
    }
    return $link;
}

Remove the post type archive feed link for a specific feed type

This example removes the post type archive feed link for the ‘atom’ feed type.

add_filter( 'post_type_archive_feed_link', 'remove_atom_feed_link', 10, 2 );

function remove_atom_feed_link( $link, $feed ) {
    if ( 'atom' === $feed ) {
        $link = '';
    }
    return $link;
}

Change the post type archive feed link based on the current user

This example changes the post type archive feed link depending on whether the user is logged in or not.

add_filter( 'post_type_archive_feed_link', 'change_feed_link_based_on_user', 10, 2 );

function change_feed_link_based_on_user( $link, $feed ) {
    if ( is_user_logged_in() ) {
        $link = 'https://example.com/logged-in-users-feed/';
    } else {
        $link = 'https://example.com/anonymous-users-feed/';
    }
    return $link;
}