You don’t have to install a completely new commenting system on your WordPress webpage in order to make your comments section different.
In one of our next articles, we will show you how to open comments in a popup window with a few WP tricks, but if you’re trying to get a slightly different solution, today we’re going to show you how to open those comments on a completely new page.
This trick will let you remove the standard comments template, create a link to a new page and then create that new page for each post so that every post can have its own comments page. If your site is heavy on comments and you rely on people’s opinion, this might create a much more dynamic environment where comments can act as discussion pages for a post that lead to it.
To make this trick work, you will be using WordPress’ popup comment script which is slightly modified in order to open a new page instead of a popup.
Now that you have decided to have comments on a separate page, let’s start customizing the system.
Remove the old commenting system:
First, you will need to remove the old comments template – If you’re opening comments on another page, you don’t want them to load the post content, right?
- Open single.php file
- Remove the line of code which loads the comments template. Don’t forget to save the code somewhere in order you make a mistake and want everything back:
- Save changes
<?php comments_template('', true); ?>
Create a link:
Now you are ready to create a link which will lead to the comments page. So far, you don’t have a page, but don’t worry; the code will create one according to each post ID:
- Open single.php file again
- Find a place where you want the link to appear (if you want the usual, place the code right after the post content:
- Change the URL on the first line
- Change text on the third line if you want to. Those three variables contain text which will be shown as link when there are no comments, when there’s only one or when there are several comments already posted.
- Save changes
<a href="http://www.yourwebsite.com/?comments_popup=<?php the_ID(); ?>" class="btn btn-primary"> <?php comments_number('There are no comments', '1 Comment', '% Comments and counting'); ?></a>
for example: <a href=”http://www.firstsiteguide.com/?comments_popup=<?php the_ID(); ?>”
Create a new PHP page for your comments in separate pages:
You are almost done. But before you can go on and test your new commenting system, you will still have to create a new PHP page which will actually contain comments for each and every post.
- Open your FTP client like FileZilla
- Go to /wp-includes/theme-compat/ where the file is usually located
- Create a new file and name it comments-popup.php
- Open source code on GitHub https://github.com/WordPress/WordPress/blob/master/wp-includes/theme-compat/comments-popup.php
- Copy and paste the code in the file
- Save changes
That’s it. Now you can test your new system, style it to your needs and add/remove content as you wish. If you have done everything correctly, your comments will now open on a new page while each post will have its own comments page with a different ID.