Using is_main_query()


is_main_query() is a new function as of ver 3.3 that allows us to target the main loop on the page, which is useful if there are several custom loops running on a page.

One basic example of its usage is for adding on to the_content filter, appending something before or after content, such as a like button or some custom text. is_main_query() ensures your addition only appears in the main query, as opposed to on each query running on the page.

Pippin Williamson does a great job of explaining its usage. I’ll leave it to him.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s