[Resolved] Suppress creator and add feature image to RSS feed

Home Forums Support [Resolved] Suppress creator and add feature image to RSS feed

Home Forums Support Suppress creator and add feature image to RSS feed

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1198796
    Steven

    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/

    #1198941
    Tom
    Lead Developer
    Lead Developer

    Hi 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.

    #1198949
    Steven

    Found 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 );
    #1199710
    Tom
    Lead Developer
    Lead Developer

    Awesome, glad you found a solution! 🙂

    #1600999
    Steven

    Revisiting 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.

    #1601003
    Steven

    Also 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

    #1601028
    Steven

    OK – 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 );   
    #1601071
    Tom
    Lead Developer
    Lead Developer

    Glad 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.

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.