1

To disable a custom post types archive page, we should use the following code:

$args = array(
    'has_archive' => false,
);

But when we use false for has_archive, the feeds page (like : name.com/books/feed) of that custom post type becomes disabled too. Now I want to know how I can disable custom post types archive page but keep the feed active?

5

Set the feeds argument of rewrite to true to generate feed rewrite rules. It defaults to whatever has_archive is set to if nothing is explicitly passed.

$args = array(
    'has_archive' => false,
    'rewrite' => array(
        'feeds' => true
    ),
    // your other args...
);
  • I use this method also but feed not generate. – saeed shabani Jan 31 '16 at 5:43
  • This is the correct answer. Be sure to flush rewrite rules after implementing this. – Spartacus Jun 9 '17 at 21:27
0

Finally I found a solution for it. I set has_archive to true. Now both the feed and the archive page of CPT are active. To only disable the archive page of CPT, I use the following filter in the functions.php file:

function AryanThemes_disable_cpt_archive_template(){
    if ( is_post_type_archive('cpt') ) {
        global $wp_query;
      $wp_query->set_404();
      status_header( 404 );
      get_template_part( 404 ); exit();
  }
}
add_filter( 'archive_template', 'AryanThemes_disable_cpt_archive_template', -1 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.