The feed_content_type WordPress PHP filter allows you to modify the content type of a specific feed type in WordPress.
Usage
add_filter( 'feed_content_type', 'my_custom_feed_content_type', 10, 2 ); function my_custom_feed_content_type( $content_type, $type ) { // your custom code here return $content_type; }
Parameters
$content_type
(string) – Content type indicating the type of data that a feed contains.$type
(string) – Type of feed. Possible values include ‘rss’, ‘rss2’, ‘atom’, and ‘rdf’.
More information
See WordPress Developer Resources: feed_content_type
Examples
Change Atom Feed Content Type
Modify the content type for Atom feeds to ‘application/atom+xml’.
add_filter( 'feed_content_type', 'change_atom_feed_content_type', 10, 2 ); function change_atom_feed_content_type( $content_type, $type ) { if ( 'atom' === $type ) { return 'application/atom+xml'; } return $content_type; }
Change RSS2 Feed Content Type
Modify the content type for RSS2 feeds to ‘application/rss+xml’.
add_filter( 'feed_content_type', 'change_rss2_feed_content_type', 10, 2 ); function change_rss2_feed_content_type( $content_type, $type ) { if ( 'rss2' === $type ) { return 'application/rss+xml'; } return $content_type; }
Set a Custom Content Type for RDF Feeds
Set a custom content type for RDF feeds to ‘application/my-custom-rdf+xml’.
add_filter( 'feed_content_type', 'set_custom_rdf_feed_content_type', 10, 2 ); function set_custom_rdf_feed_content_type( $content_type, $type ) { if ( 'rdf' === $type ) { return 'application/my-custom-rdf+xml'; } return $content_type; }
Modify Content Type for All Feed Types
Add a custom suffix to the content type for all feed types.
add_filter( 'feed_content_type', 'modify_all_feed_content_types', 10, 2 ); function modify_all_feed_content_types( $content_type, $type ) { return $content_type . '; custom_suffix'; }
Remove Custom Suffix from Content Type
Remove a custom suffix from the content type for a specific feed type (e.g., ‘rss’).
add_filter( 'feed_content_type', 'remove_custom_suffix_from_content_type', 10, 2 ); function remove_custom_suffix_from_content_type( $content_type, $type ) { if ( 'rss' === $type ) { return str_replace( '; custom_suffix', '', $content_type ); } return $content_type; }