in_the_loop()WP 2.0.0

Determines whether the caller is in The Loop (i.e. whether the loop is currently active). A conditional tag that is used to execute code only inside The Loop.

No Hooks.


true|false. True if caller is within loop, false if loop hasn't started or ended.


if( in_the_loop() ){
	// we inside the loop...


#1 Change post title

The below example shows how to add a hook that changes the title when the_title() function is used within The Loop.

add_filter( 'the_title', 'modify_single_post_entry_titles' );

function modify_single_post_entry_titles( $title ) {

	if ( is_singular( 'post' ) && in_the_loop() ) {
		// Change title
		$title = 'A new title.';

	return $title;


  • Global. WP_Query. $wp_query WordPress Query object.


Since 2.0.0 Introduced.

Code of in_the_loop() WP 6.0

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