Created
April 24, 2014 14:24
-
-
Save nciske/11256451 to your computer and use it in GitHub Desktop.
disable feeds for a specific CPT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'init', 'register_cpt_test' ); | |
function register_cpt_test() { | |
$labels = array( | |
'name' => _x( 'tests', 'test' ), | |
'singular_name' => _x( 'test', 'test' ), | |
'add_new' => _x( 'Add New', 'test' ), | |
'add_new_item' => _x( 'Add New test', 'test' ), | |
'edit_item' => _x( 'Edit test', 'test' ), | |
'new_item' => _x( 'New test', 'test' ), | |
'view_item' => _x( 'View test', 'test' ), | |
'search_items' => _x( 'Search tests', 'test' ), | |
'not_found' => _x( 'No tests found', 'test' ), | |
'not_found_in_trash' => _x( 'No tests found in Trash', 'test' ), | |
'parent_item_colon' => _x( 'Parent test:', 'test' ), | |
'menu_name' => _x( 'tests', 'test' ), | |
); | |
$args = array( | |
'labels' => $labels, | |
'hierarchical' => false, | |
'supports' => array( 'title', 'editor' ), | |
'public' => true, | |
'show_ui' => true, | |
'show_in_menu' => true, | |
'show_in_nav_menus' => false, | |
'publicly_queryable' => true, | |
'exclude_from_search' => false, | |
'has_archive' => true, | |
'query_var' => true, | |
'can_export' => true, | |
'rewrite' => true, | |
'capability_type' => 'post' | |
); | |
register_post_type( 'test', $args ); | |
} | |
// disable all feeds | |
function digwp_disable_feed() { | |
if( is_feed() && is_post_type_archive('test') ) // or use get_post_type() == 'test' | |
wp_die(__('<h1>Feed not available, please visit our <a href="'.get_bloginfo('url').'">Home Page</a>!</h1>')); | |
} | |
add_action('do_feed', 'digwp_disable_feed', 1); | |
add_action('do_feed_rdf', 'digwp_disable_feed', 1); | |
add_action('do_feed_rss', 'digwp_disable_feed', 1); | |
add_action('do_feed_rss2', 'digwp_disable_feed', 1); | |
add_action('do_feed_atom', 'digwp_disable_feed', 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adapted from
http://digwp.com/2012/10/customizing-wordpress-feeds/#customize-filters-hooks
in response to
https://www.facebook.com/groups/advancedwp/permalink/712330335495850/