1. Home
  2. »
  3. WordPress Tutorials
  4. »
  5. How to Disable WordPress Comments on Specific Posts

How to Disable WordPress Comments on Specific Posts

When running a WordPress website, you may come across situations where you want to disable comments on specific posts. This can be easily achieved by using a simple code snippet in your theme’s functions.php file. Let’s walk through the steps to disable comments on specific posts:

Step 1: Find the Post ID

First, you need to find the post ID of the specific post where you want to disable comments. You can do this by going to your WordPress dashboard, navigating to the Posts section, and clicking on the post you want to target. In the URL, you will see something like https://yourwebsite.com/wp-admin/post.php?post=123&action=edit. The number after post= is the post ID.

Step 2: Add Code Snippet to functions.php

Now, open your theme’s functions.php file and add the following code snippet:

      
      
      function flashify_disable_comments_specific_post( $open, $post_id ) {
        if ( $post_id === 123 ) { // Replace 123 with your actual post ID
          return false;
        }
        return $open;
      }
      add_filter( 'comments_open', 'flashify_disable_comments_specific_post', 10, 2 );
      
      

This code snippet creates a function flashify_disable_comments_specific_post that checks if the post ID matches the ID you specified (in this case, 123). If it does, it returns false to disable comments on that specific post.

Step 3: Replace Post ID and Test

Make sure to replace 123 with the actual post ID you want to target. Save the changes to your functions.php file and refresh the specific post in your browser. You should now see that comments are disabled for that post.

By following these steps and using the provided code snippet, you can easily disable comments on specific posts in WordPress. This can be useful for various reasons, such as turning off comments on outdated posts or posts where comments are not relevant.

For more WordPress tutorials and plugin development tips, check out our website.

Shashika De Silva

Shashika De Silva

Hey there! I’m a seasoned PHP developer with over 10 years of experience crafting awesome WordPress plugins and themes. I specialize in creating scalable and robust solutions for WordPress and WooCommerce, ensuring everything runs smoothly. Whether it’s cross-platform software development, web development, or diving into Sheets/Excel with Appscript, Macros, and VBA, I’ve got you covered. I’m all about delivering top-notch results that go beyond expectations. Let’s team up and turn your ideas into reality, making your project shine! Looking forward to working together and achieving something remarkable!

Select By Category

Flashify.Lab

Join our team
to create the best digital solutions.

Enhance your WordPress site’s functionality with custom plugins tailored to your unique needs. Our expert developers specialize in creating robust plugins that seamlessly integrate with WooCommerce, ensuring a streamlined user experience and enhanced site performance. Transform your ideas into reality with our bespoke plugin development services today

Scroll to Top