- This topic has 7 replies, 2 voices, and was last updated 3 years, 2 months ago by Tom.
-
AuthorPosts
-
March 18, 2020 at 12:06 pm #1198796Steven
We’re trying to modify all of the default RSS feeds for our site. For example:
https://mydomain.com/feed/
https://mydomain.com/news/topics/government/feed/
etc.Is there a way to override using a GP child theme? We didn’t readily see an option to customize the RSS feed in the GP customizer. We found the following resources, but haven’t been able to get the changes we’re looking for (suppress creator and include feature image 150×150 thumbnails) to work:
https://generatepress.com/forums/topic/no-image-captions-in-rss-feed/
https://wordpress.org/support/topic/how-to-edit-the-rss-feed-output/
https://www.wpbeginner.com/wp-tutorials/how-to-create-custom-rss-feeds-in-wordpress/March 18, 2020 at 4:17 pm #1198941TomLead DeveloperLead DeveloperHi there,
This isn’t something the theme controls, but there are plugins out there:
https://wordpress.org/plugins/rss-featured-image/I wonder if the theme controls the author display.. We could try this:
add_filter( 'generate_post_author_output', function( $output ) { if ( is_feed() ) { return ''; } return $output; } );
Not sure if that will work or not, but it’s worth a shot.
March 18, 2020 at 4:45 pm #1198949StevenFound this: https://wordpress.stackexchange.com/questions/47726/remove-or-edit-dccreator-in-feeds
I ended up going with the code below in our functions.php file to set the author to a static value. Seems to be working. I’ll look in to the plugin for adding the feature images.
Thanks Tom!
//Set author for RSS feeds function set_the_author( $display_name ) { if ( is_feed() ) { return 'My Static Author Name'; } } add_filter( 'the_author', 'set_the_author', PHP_INT_MAX, 1 );
March 19, 2020 at 9:20 am #1199710TomLead DeveloperLead DeveloperAwesome, glad you found a solution! 🙂
December 31, 2020 at 10:48 am #1600999StevenRevisiting this need. We thought using “the_author” function was working. It does, however the Author field in the Media Library, Posts view, etc. gets blanked out (no value is shown) when the following is added to our child theme functions.php:
//Set author for RSS feeds function mod_author( $display_name ) { if ( is_feed() ) { return 'New Author'; } } add_filter( 'the_author', 'mod_author', PHP_INT_MAX, 1 );
We tried Tom’s suggestion and it doesn’t appear to affect a change to the RSS feeds:
add_filter( 'generate_post_author_output', function( $output ) { if ( is_feed() ) { return 'New Author'; } return $output; } );
Thanks for any tips you can pass along.
December 31, 2020 at 10:58 am #1601003StevenAlso tried the following, but get an error when trying to view the RSS feed:
https://wordpress.stackexchange.com/questions/47726/remove-or-edit-dccreator-in-feeds
December 31, 2020 at 12:02 pm #1601028StevenOK – I think the following seems to be working. It allows you to customize a copy of the feed-rss2.php template and doesn’t blank out the Author column in the Media Library, Pages list, etc.
1) Copy the feed-rss2.php from the wp-includes directory to your child theme directory.
2) Modify the feed-rss2.php as desired.
3) Add the following to your child theme’s functions.php file//Load custom RSS feeds template remove_all_actions( 'do_feed_rss2' ); add_action( 'do_feed_rss2', function( $for_comments ) { if ( $for_comments ) load_template( ABSPATH . WPINC . '/feed-rss2-comments.php' ); else { if ( $rss_template = locate_template( 'feed-rss2.php' ) ) // locate_template() returns path to file // if either the child theme or the parent theme have overridden the template load_template( $rss_template ); else load_template( ABSPATH . WPINC . '/feed-rss2.php' ); } }, 10, 1 );
December 31, 2020 at 12:58 pm #1601071TomLead DeveloperLead DeveloperGlad you found a solution – thanks for sharing it. This isn’t something I’ve worked with a bunch, but it’s good to know you’re able to overwrite the template like that.
-
AuthorPosts
- You must be logged in to reply to this topic.