the_content-is-not-working in WordPress: – the_content () is a WordPress function to show the content of the page. When we build a custom post or develop a custom theme for our website then we need to show the content of page template or need to show content in the single.php file for the blog post. But sometimes its happened that the_content is not working in WordPress on template file or single.php file. Maybe the_title() is working but not showing the content of the single post.

the_content-is-not-working in wordpress

the_content-is-not-working in WordPress on template file or single.php file

To understand the problem why the_content not working on the template file we need to understand that how the_content function actually working.

Well, WordPress uses a loop to show the posts on any page. Usually, we show our post in an index.php file or any other file where we need. Here is the most simple WordPress post loop to show the post.

<?php if ( have_posts() ) : ?>
    <?php while ( have_posts() ) : the_post(); ?>
        ... Display post content
    <?php endwhile; ?>
<?php endif; ?>

WordPress loop is very simple and easy to use.

So why the_content is not working in WordPress on single.php file or template file? when you write the code like below

<div id="content" role="main">
    <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
        <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>     

        <div class="entry">
            <?php the_content(); ?>
        </div>
    </div>   
</div><!-- #content -->

When we write this code in a single.php file or any template file it shows the title of the post but not showing the content of the post. But if you use the array of the post we will see the post is here but not show.

Our code is perfectly right but the_content now working. The solution of is very simple.

the_content () function needs to be in a WordPress loop, there will be an if else condition and the post loop. But anyone may be confused about the else part. When we are writing the code in a single.php file that means we have already a post in the single.php file.  So, no need to use the else part. just use the if part.

<div id="content" role="main">
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
        <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
        <div class="entry">
            <?php the_content(); ?>
        </div>
    </div>
    <?php endwhile; endif; ?>
</div><!-- #content -->

If everything is ok then “the_content-is-not-working in WordPress” will be solved and the content of single.php or in WordPress template file will show perfectly.

Thank you for reading the article. For more fresh WordPress tips connected with Your WordPress Expert.