Moving comments in Toocheke theme

I had a friend ask me if I could help them move their comments section on the homepage of Toocheke theme. The location of comments happening after the creator’s thoughts/blog post about the comic seemed like a strange placement to me too. I thought I’d publish the solution here in case anyone else wanted to move this section around!

Step 1: Make sure you’re using a child theme

If you don’t know already, child themes “inherit” things from their parent theme. It’s a way to safely make changes to a theme without losing them all if the theme is ever updated. You can set up a child theme manually, or use a plugin like Child Theme Configurator to make a child theme of your current theme.

Got a child theme? Good. Let’s get to work.

Step 2: Copy appropriate files into the child theme

What we’re going to be doing is moving some sections of code from one file to the other.

For this, you’ll need to copy these two files:

  • template-parts/content-traditionalcomicnavigation.php
  • template-parts/content-latestcomicblog.php

Step 3: Edit content-traditionalcomicnavigation.php

In template-parts/content-traditionalcomicnavigation.php, copy line 13 and save it somewhere like a text document. That line should be:

$allow_home_comments = get_option('toocheke-comic-discussion');

Then, scroll down and copy lines 129 to the end of the file. Save those somewhere too, and then delete all those lines. You should have this section of code now saved:

<?php
if (($allow_home_comments === '1' && is_home() && $below_comic) || ($allow_home_comments === '1' && is_singular('series'))) {
?>
<div id="comments-wrapper" class="row">
<div class="col-lg-12">
<?php
global $withcomments;
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
$withcomments = "1";
comments_template();
?>
</div>
</div>
<?php
}
?>

Save the file with the modifications. If you check your website, the comments should be completely gone on the homepage.

Step 4: Edit content-latestcomicblog.php

Now, open template-parts/content-latestcomicblog.php. Make a new line after line 8, and paste in the $allow_home_comments line we saved in the first step.

Scroll to line 74, and after </article>, paste in the second bit of PHP code that we saved in the first step.

Save the file, and now your comments should appear beneath the blog content as well as next to the sidebar.

Subscribe to Foundation!

Sign up now to get notifications when new posts are made including tips, tricks, tutorials, and more. You can unsubscribe at any time! I'll never sell or share your email address.