Created
June 28, 2014 07:28
-
-
Save palpalani/f7ba52f5228f2c28988e to your computer and use it in GitHub Desktop.
WordPress - Checking If You're in the Loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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