Remove sticky posts from main loop

/**
 * Remove sticky posts from main loop
 * @author Bill Erickson 
 * @link https://www.billerickson.net/code/remove-sticky-posts-main-loop/
 *
 * @param object $query
 */
function ea_remove_sticky_from_main_loop( $query ) {
	if( $query->is_main_query() && ! is_admin() ) {
		$query->set( 'ignore_sticky_posts', true );
	}
}
add_action( 'pre_get_posts', 'ea_remove_sticky_from_main_loop' );
Bill Erickson

Bill Erickson is the co-founder and lead developer at CultivateWP, a WordPress agency focusing on high performance sites for web publishers.

About Me
Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk