Modifying the default WordPress loop to exclude specific post formats

To modify the default WordPress loop to not display posts with a specific post format on the homepage, add the following to the theme’s functions.php file:

function exclude_post_formats( $query ) {
	if ( $query->is_main_query() && $query->is_home() ) {
		$tax_query = array(
				'taxonomy' => 'post_format',
				'field' => 'slug',
				'terms' => array(
				'operator' => 'NOT IN',
		$query->set( 'tax_query', $tax_query );

add_action( 'pre_get_posts', 'exclude_post_formats' );

So, what’s going on here? In short, we’re modifying the existing WP loop on the homepage by adding a custom filter function prior to getting the posts (i.e. executing the query).

Modifying the query is accomplished by calling the set method of WP_Query and updating the tax_query variable with our desired values. In this case, I only wanted to exclude posts with an aside format, but, since it’s an array, I could have excluded multiple format types.

If, for some reason, you wanted to not display a specific post format in the search results or in any secondary query (in other words, never), remove the condtional that wraps the exclude_post_formats body.

Full documentation on tax_query is located in the WordPress Codex at

Technique from