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.