How to show wordpress pages on front page with skip_home custom field

By default WordPress pages donot show up on home page. Only posts are displayed on home page. Here is wordpress php code which can be used to show wordpress pages on home page.

function pre_get_posts_home($query) {
  if (is_home() && $query->query_vars['suppress_filters'] == FALSE) {
    $query->set('post_type', array('post', 'page'));
    // skip if skip_home=1
    $meta_query = $query->get('meta_query');
    $meta_query[] = array(
                    'compare'=>'NOT EXISTS',
add_action('pre_get_posts', 'pre_get_posts_home');

Note that $query->query_vars['suppress_filters'] check is needed as there are other queries on home page for getting items for menu, etc. We don’t want to change those queries.

Skipping specific page from home page

To skip a page add skip_home custom field (meta_key) with any value as shown below:

Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit


Click here to write/view comments