• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP SITES

2662

Original Genesis Tutorials & 5000+ Guaranteed Code

Snippets

  • Support
  • Newsletter
  • Videos
  • Log in

Premium Member? - Request custom code

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

  • Only Show Specific Pages or Posts On Home Page

pre_get_posts

Reader Interactions

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

PHP Code

template_include

get_body_class

if else

array

class_exists

foreach

sprintf

add_action

printf

variable

Advertise · WPEngine · Genesis · Log in

  • How Premium Membership Works
  • Sign Up
  • Support
  • Subscription Details/Invoice
  • Tagged Tutorials
  • Access-Download Problems