in_the_loop() WordPress Function

The in_the_loop() function is used to check whether the current code is within a WordPress Loop. If a Loop has not yet started, this function will return false. Otherwise, it will return true. This function can be useful for making sure that certain code is only run when a Loop is active.

in_the_loop() #

Determines whether the caller is in the Loop.


Description

For more information on this and similar theme functions, check out the Conditional Tags article in the Theme Developer Handbook.


Top ↑

Return

(bool) True if caller is within loop, false if loop hasn't started or ended.


Top ↑

Source

File: wp-includes/query.php

function in_the_loop() {
	global $wp_query;
	return $wp_query->in_the_loop;
}


Top ↑

Changelog

Changelog
VersionDescription
2.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.