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.
Return
true/false. True if caller is within loop, false if loop hasn't started or ended.
Usage
if( in_the_loop() ){ // we inside the loop... }
Examples
#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; }
Notes
- Global. WP_Query. $wp_query WordPress Query object.
Changelog
Since 2.0.0 | Introduced. |
Code of in_the_loop() in the loop WP 5.6
function in_the_loop() {
global $wp_query;
return $wp_query->in_the_loop;
}Related Functions
From tag: Conditional tags (all)
- cat_is_ancestor_of()
- comments_open()
- email_exists()
- has_category()
- has_custom_header()
- has_excerpt()
- has_nav_menu()
- has_post_thumbnail()
- has_shortcode()
- has_tag()
- has_term()
- have_comments()
- have_posts()
- in_category()
- is_404()
- is_active_sidebar()
- is_admin()
- is_admin_bar_showing()
- is_archive()
- is_attachment()
- is_author()
- is_blog_admin()
- is_blog_installed()
- is_category()
- is_child_theme()
- is_comment_feed()
- is_customize_preview()
- is_date()
- is_day()
- is_dynamic_sidebar()
- is_embed()
- is_feed()
- is_front_page()
- is_header_video_active()
- is_home()
- is_local_attachment()
- is_main_query()
- is_month()
- is_multi_author()
- is_multisite()
- is_nav_menu()
- is_network_admin()
- is_new_day()
- is_page()
- is_page_template()
- is_paged()
- is_plugin_active()
- is_post_type_archive()
- is_post_type_hierarchical()
- is_preview()
- is_robots()
- is_search()
- is_single()
- is_singular()
- is_ssl()
- is_sticky()
- is_tag()
- is_tax()
- is_taxonomy_hierarchical()
- is_textdomain_loaded()
- is_time()
- is_trackback()
- is_user_admin()
- is_user_logged_in()
- is_year()
- pings_open()
- post_exists()
- post_password_required()
- shortcode_exists()
- taxonomy_exists()
- term_exists()
- term_is_ancestor_of()
- wp_attachment_is()
- wp_attachment_is_image()
- wp_doing_ajax()
- wp_doing_cron()
- wp_is_mobile()
- wp_is_post_autosave()
- wp_is_post_revision()
- wp_script_is()
More from category: Queries
More from Template Tags: Posts, Pages, ...
- body_class()
- get_post_format()
- get_post_time()
- get_the_date()
- next_image_link()
- next_post_link()
- next_posts_link()
- post_class()
- posts_nav_link()
- previous_image_link()
- previous_post_link()