Skip to content

Instantly share code, notes, and snippets.

@jaredatch
Last active February 8, 2022 05:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaredatch/8610187 to your computer and use it in GitHub Desktop.
Save jaredatch/8610187 to your computer and use it in GitHub Desktop.
<?php
/**
* Disable the "foo" custom post type feed
*
* @since 1.0.0
* @param object $query
*/
function ja_disable_cpt_feed( $query ) {
if ( $query->is_feed() && in_array( 'foo', (array) $query->get( 'post_type' ) ) ) {
die( 'Feed disabled' );
}
}
add_action( 'pre_get_posts', 'ja_disable_cpt_feed' );
@SRD75
Copy link

SRD75 commented Feb 8, 2022

Our custom post slug is templates. I've added the following to our child theme's functions.php, but the CPT feed is still there.

function mandoe_disable_cpt_feed( $query ) {
	if ( $query->is_feed() && in_array( 'templates', (array) $query->get( 'post_type' ) ) ) {
		die( 'Feed disabled' );
	}
}
add_action( 'pre_get_posts', 'mandoe_disable_cpt_feed' );

I've resaved the Permalinks, and the issue remains.

Help appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment