WP SITES

3082 Coded Tutorials & 283 Plugins

Include Single Pages With Posts In Home Page Loop

This code laters the main query for the home page loop to include single pages with posts.

Add the PHP code to the end of your child themes functions.php file

add_filter( 'pre_get_posts', 'include_pages_in_loop' );

function include_pages_in_loop( $query ) {

  if ( ! is_admin() && is_home() && $query->is_main_query() ) {
  
  $query->set('post_type', array( 'post', 'page' ) );
  
  }
  
}

Adds the page post type to the original query before it runs so single pages are included with single posts in the home page loop.

Related Tutorials

Leave a Reply

New Plugins