Disable RSS Feeds

Turn off the WordPress RSS Feeds for your website with 1 click.

Use Snippet
php
<?php
/**
 * Display a custom message instead of the RSS Feeds.
 *
 * @return void
 */
function wpcode_snippet_disable_feed() {
	wp_die(
		sprintf(
			// Translators: Placeholders for the homepage link.
			esc_html__( 'No feed available, please visit our %1$shomepage%2$s!' ),
			' <a href="' . esc_url( home_url( '/' ) ) . '">',
			'</a>'
		)
	);
}
// Replace all feeds with the message above.
add_action( 'do_feed_rdf', 'wpcode_snippet_disable_feed', 1 );
add_action( 'do_feed_rss', 'wpcode_snippet_disable_feed', 1 );
add_action( 'do_feed_rss2', 'wpcode_snippet_disable_feed', 1 );
add_action( 'do_feed_atom', 'wpcode_snippet_disable_feed', 1 );
add_action( 'do_feed_rss2_comments', 'wpcode_snippet_disable_feed', 1 );
add_action( 'do_feed_atom_comments', 'wpcode_snippet_disable_feed', 1 );
// Remove links to feed from the header.
remove_action( 'wp_head', 'feed_links_extra', 3 );
remove_action( 'wp_head', 'feed_links', 2 );
WPCode Team
900+

Add Featured Images to RSS Feeds

Extend your site's RSS feeds by including featured images in the feed.

Use Snippet
php
<?php
/**
 * Add the post thumbnail, if available, before the content in feeds.
 *
 * @param string $content The post content.
 *
 * @return string
 */
function wpcode_snippet_rss_post_thumbnail( $content ) {
	global $post;
	if ( has_post_thumbnail( $post->ID ) ) {
		$content = '<p>' . get_the_post_thumbnail( $post->ID ) . '</p>' . $content;
	}
	return $content;
}
add_filter( 'the_excerpt_rss', 'wpcode_snippet_rss_post_thumbnail' );
add_filter( 'the_content_feed', 'wpcode_snippet_rss_post_thumbnail' );
WPCode Team
600+

Exclude Specific Categories from RSS Feed

Prevent posts in certain categories from showing up in your RSS Feeds.

Use Snippet
php
<?php
/**
 * Exclude a category or multiple categories from the feeds.
 * If you want to exclude multiple categories, use a comma-separated list: "-15, -5, -6".
 * Make sure to prefix the category id(s) with a minus "-".
 *
 * @param WP_Query $query The query.
 */
function wpcode_snippets_exclude_feed_category( $query ) {
	if ( $query->is_feed ) {
		// Replace 15 with the desired category id you want to exclude.
		$query->set( 'cat', '-15' );
	}
}
add_action( 'pre_get_posts', 'wpcode_snippets_exclude_feed_category' );
WPCode Team
90+

Delay Posts in RSS Feeds

Add a delay before published posts show up in the RSS feeds.

Use Snippet
php
<?php
function wpcode_snippet_publish_later_on_feed( $where ) {
	global $wpdb;
	if ( is_feed() ) {
		// Timestamp in WP-format.
		$now = gmdate( 'Y-m-d H:i:s' );
		// Number of unit to wait
		$wait = '10'; // integer.
		// Choose time unit.
		$unit = 'MINUTE'; // MINUTE, HOUR, DAY, WEEK, MONTH, YEAR.
		// Add SQL-sytax to default $where. By default 10 minutes.
		$where .= " AND TIMESTAMPDIFF($unit, $wpdb->posts.post_date_gmt, '$now') > $wait ";
	}
	return $where;
}
add_filter( 'posts_where', 'wpcode_snippet_publish_later_on_feed' );
WPCode Team
80+