Using WordPress ‘get_tag_feed_link()’ PHP function

The get_tag_feed_link() WordPress PHP function retrieves the permalink for a specific tag feed.

Usage

get_tag_feed_link( $tag, $feed );

Custom Example

$link = get_tag_feed_link( 1, 'rss2' );
echo $link; // Output: https://example.com/tag/tag_name/feed/rss2

Parameters

  • $tag (int|WP_Term|object): Required. The ID or term object whose feed link will be retrieved.
  • $feed (string): Optional. Feed type. Possible values include ‘rss2’, ‘atom’. Default is the value of get_default_feed(). Default: ”.

More information

See WordPress Developer Resources: get_tag_feed_link()

Examples

This example retrieves the RSS2 feed link for the tag with the ID 5 and displays it.

// Retrieve the RSS2 feed link for the tag with ID 5
$tag_feed_link = get_tag_feed_link( 5, 'rss2' );

// Display the RSS2 feed link
echo $tag_feed_link;

This example retrieves the Atom feed link for a tag using a WP_Term object and displays it.

// Get the WP_Term object for the tag with ID 3
$tag_object = get_term( 3, 'post_tag' );

// Retrieve the Atom feed link for the tag
$tag_feed_link = get_tag_feed_link( $tag_object, 'atom' );

// Display the Atom feed link
echo $tag_feed_link;

This example retrieves the default feed link for a tag using its name and displays it.

// Get the tag object by its name
$tag_object = get_term_by( 'name', 'technology', 'post_tag' );

// Retrieve the default feed link for the tag
$tag_feed_link = get_tag_feed_link( $tag_object );

// Display the default feed link
echo $tag_feed_link;

This example retrieves and displays the RSS2 feed link for all tags.

// Get all tags
$tags = get_tags();

// Loop through each tag and display the RSS2 feed link
foreach ( $tags as $tag ) {
    $tag_feed_link = get_tag_feed_link( $tag->term_id, 'rss2' );
    echo $tag_feed_link . '<br>';
}

This example retrieves the Atom feed link for a tag using its slug and displays it.

// Get the tag object by its slug
$tag_object = get_term_by( 'slug', 'web-development', 'post_tag' );

// Retrieve the Atom feed link for the tag
$tag_feed_link = get_tag_feed_link( $tag_object, 'atom' );

// Display the Atom feed link
echo $tag_feed_link;