August 16, 201511 yr In my theme, if I use this code: echo '<h3 class="posttitle">' . the_title() . '</h3>'; What I get is: The title <h3 class="posttitle"></h3> What I was expecting: <h3 class="posttitle">The title</h3> Also, similar problem here: else if ( in_category( 'reviews' ) ) { echo 'Latest review: ' . the_title(); } This displays the wrong way around. So, 'The title Latest review:' rather than 'Latest review: The title' Any ideas?
August 16, 201511 yr Asuming you are talking about WordPress, you don't need echo. The the_title() method has the "echoing" build in. Also make sure you call the method from within the loop: <?php // Start the Loop. while ( have_posts() ) : the_post(); ?> <h3><?php the_title() ?></h3> <!--You get the content the same way--> <div><?php the_content() ?></div> <?php endwhile; //the loop ends here. You can not call the methods outside the loop ?> Edited August 16, 201511 yr by Nillervision
August 16, 201511 yr Author The the_title() method has the "echoing" build in. Oh! Well, that explains it. Thanks, Nillervision
August 18, 201511 yr There's also of course the get_the_title() function which will return rather than echo the post title.
Create an account or sign in to comment