Advertisement
Guest User

Untitled

a guest
Oct 31st, 2022
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1. <?php
  2.  
  3. add_action( 'wp', 'remove_comments_feed_for_posts' );
  4. function remove_comments_feed_for_posts() {
  5.     if ( is_singular( 'post' ) ) {
  6.         remove_action('wp_head', 'feed_links_extra', 3 );
  7.     }
  8. }
  9.  
  10. add_action( 'template_redirect', 'disable_comment_feed_for_posts' );
  11. function disable_comment_feed_for_posts() {
  12.     if ( is_comment_feed () && get_post_type() === 'post' ) {
  13.         global $wp_query;
  14.  
  15.         // Mark the current query as a 404
  16.         $wp_query->set_404();
  17.  
  18.         // Return 404 HTTP status code instead of the default 200
  19.         status_header(404);
  20.        
  21.         // By default, this page returns XML, so we change the Content-Type header
  22.         // Because we want to show a 404 page
  23.         header('Content-Type: text/html; charset=utf-8');
  24.  
  25.         // Render the 404 template
  26.         get_template_part( 404 );
  27.  
  28.         // You should exit from the script after that
  29.         exit();
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement