What is The Loop in WordPress?

The Loop is a term used in the WordPress community to describe the internal cycle used to display each of your posts. Using The Loop, WordPress processes all posts and displays them on the current page, formatted and filtered. Any HTML, PHP or other code placed within The Loop will be repeated on each post.

The most simple example of The Loop is the following code:

<?php if ( have_posts() ): while ( have_posts() ) : the_post(); ?>
<?php endwhile; endif; ?>

The Loop is the main part of each theme - it is the core of each WordPress site. If you find a instruction to place piece of code "within The Loop" you should place it before the endwhile; element that closes the cycle.

WordPress is a trademark of WordPress Foundation. SiteGround is not affiliated with or endorsed by the WordPress Project or its trademark owners.