Skip to content

Instantly share code, notes, and snippets.

@michaelbragg
Created October 1, 2021 07:14
Show Gist options
  • Save michaelbragg/e2ee6844bc4bf93013238bd4a496e23e to your computer and use it in GitHub Desktop.
Save michaelbragg/e2ee6844bc4bf93013238bd4a496e23e to your computer and use it in GitHub Desktop.
[WordPress] Themes: Populate the 'Posts Page' with content from the Editor.
<?php
/**
* Pull content from Posts Page into home template.
*
* @param WP_Query $query WP Query.
*
* @return WP_Query
*/
function ti_load_home_content( $query ) {
// Discard if not the main query.
if ( ! $query->is_main_query() ) {
return;
}
// Stop if this is inside the WP Admin area.
if ( is_admin() ) {
return;
}
// Stop if we are not on the home (post archive) page.
if ( ! is_home() ) {
return;
}
$query->set( 'post_type', 'page' );
$query->set( 'p', get_option( 'page_for_posts' ) );
return $query;
}
add_action(
'pre_get_posts',
'ti_load_home_content'
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment