Skip to content

Instantly share code, notes, and snippets.

@palpalani
Created June 28, 2014 07:28
Show Gist options
  • Save palpalani/f7ba52f5228f2c28988e to your computer and use it in GitHub Desktop.
Save palpalani/f7ba52f5228f2c28988e to your computer and use it in GitHub Desktop.
WordPress - Checking If You're in the Loop
Both theme and plugin developers might need to check if their code is going to be run in the Loop or not. As the name suggests, the in_the_loop() function provides the answer easily.
Usage
<?php
if( in_the_loop() ) {
// do something loop-related
} else {
// don't do anything or display some kind of error/warning
}
?>
Probably the easiest one to use among the functions in this article, along with wp_is_mobile().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment