Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSashana Maitland-Walker
158 PointsMy comment section isn't being remove when I comment it out in the page.php file.
Hi,
I have been trying to comment out the comments section for a page in the page.php. I've tried this type of commenting out <?php //comments_template(); ?> and also this <?php /*comments_template(); */ ?>. I do this using Sublime Text 2, save it, and then upload the new page template to /jream/wp-content/themes/twentythirteen-child with FileZilla. I already tried to change the colour of my nav bar to the brown colour and it worked, so I wonder if I need to do something extra. Help lol
3 Answers
Brian Hayes
20,986 PointsI just set up a quick child theme for twentythirteen in my local dev environment. All I have are three files in it. functions.php
, page.php
, and style.css
.
I commented out the comment_template()
function and it worked just fine. My file contents are as follows:
functions.php
<?php
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
style.css
/*
Theme Name: Twenty Thirteen Child
Template: twentythirteen
Version: 1.0.0
*/
page.php
<?php
get_header(); ?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php if ( has_post_thumbnail() && ! post_password_required() ) : ?>
<div class="entry-thumbnail">
<?php the_post_thumbnail(); ?>
</div>
<?php endif; ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
</header><!-- .entry-header -->
<div class="entry-content">
<?php the_content(); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentythirteen' ) . '</span>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>' ) ); ?>
</div><!-- .entry-content -->
<footer class="entry-meta">
<?php edit_post_link( __( 'Edit', 'twentythirteen' ), '<span class="edit-link">', '</span>' ); ?>
</footer><!-- .entry-meta -->
</article><!-- #post -->
<?php //comments_template(); ?>
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
The only thing I can think is that, in your case, you have a syntax error somewhere, or a naming convention issue. Without seeing your child theme I can't say exactly what's wrong, but if making changes to your child themes page.php
file is not affecting changes to your page output, then for some reason that template is being ignored.
Another possibility could be that a plugin you have installed is inserting the function for comments itself. Jetpack is an example of a plugin that could be affecting the output of your plugins, as it takes the place of the normal comment template created by the theme.
Brian Hayes
20,986 PointsComments can be turned off on pages from the WordPress admin area. Also as of the most recent release, 4.3, comments on pages are now turned off by default. Now if you really just want to force it via using a page.php
file in your child theme then you need to make sure you are using the correct method for commenting out the function. Below is code I pulled from the twentythirteen theme, since that's what you're modifying. More specifically these are lines 41-47 of page.php
What you need to make sure of is that you actually comment out the function in the inline php. You can do this by simply adding //
before the function, as seen below.
</footer><!-- .entry-meta -->
</article><!-- #post -->
<?php //comments_template(); ?>
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #primary -->
Really though, it would probably be better to simply delete the line all together. I say this because this is a template that resides in you're child theme and is basically a copy of the parent theme's template with a few modifications. This means that if you need a reference for how the file originally looked, then it would be easy enough to pull up the parent theme's page template and compare the two. This is especially easy if you are using Sublime Text as you can set up columns and have the files site side by side.
Sashana Maitland-Walker
158 PointsHi, thanks for your reply. That's exactly what I did and comments_template(); went grey with the // in front of it. I have even tried deleting the entire php <?php comments_template(); ?>
line and that doesn't work.
Sashana Maitland-Walker
158 PointsAhhh, I see. Ok. I really wanted to try to just comment it out but I'm getting impatient and I think I'll just try it another time and just disable it from the WP edit side for now. I'll try it again when I'm doing another site :D. Thanks a lot for helping me though and if I do get back to it and I happen to figure out what actually went wrong then I'll let you know. Much appreciated. :)