apply_filters( ‘author_feed_link’, string $link, string $feed )

Filters the feed link for a given author.

Parameters

$linkstring
The author feed link.
$feedstring
Feed type. Possible values include 'rss2', 'atom'.

Source

$link = apply_filters( 'author_feed_link', $link, $feed );

Changelog

VersionDescription
1.5.1Introduced.

User Contributed Notes

  1. Skip to note 2 content

    In this tutorial, you will learn how to use the apply_filters function with the author_feed_link filter to modify the author feed link based on multiple conditions in WordPress. This can be useful if you want to customize the feed link for specific authors, feed types, or other criteria.

    Add the following code to your theme’s functions.php file or your custom plugin file to hook into the author_feed_link filter and modify the feed link based on multiple conditions.

    add_filter( 'author_feed_link', 'wpdocs_author_feed_link', 10, 2 );
    
    function wpdocs_author_feed_link( $link, $feed ) {
        // Condition 1: Check for a specific author by ID
        $author_id = get_query_var( 'author' );
        $specific_author_ids = array( 1, 2, 3 ); // Replace with your specific author IDs
        $author = get_user_by( 'ID', $author_id );
    
        if ( in_array( $author_id, $specific_author_ids ) ) {
            $link = add_query_arg( 'wpdocs_param', 'value', $link );
        }
    
        // Condition 2: Check for a specific feed type
        if ( 'rss2' === $feed ) {
            $link = add_query_arg( 'feed_type', 'rss2_custom', $link );
        }
    
        // Condition 3: Check if the author has a specific role
        if ( in_array( 'editor', (array) $author->roles ) ) {
            $link = add_query_arg( 'role', 'editor', $link );
        }
    
        // Additional customizations can be added here
    
        return $link;
    }

You must log in before being able to contribute a note or feedback.