Skip to content

Instantly share code, notes, and snippets.

Last active May 6, 2018
What would you like to do?
Set post as front page.
add_action('pre_get_posts', function($q){
// Check to see if static page is set for the homepage.
if (!is_admin() && $q->is_main_query() && 'page' === get_option('show_on_front')) {
//Determine if current post is homepage
if ($q->get("page_id") == get_option("page_on_front")) {
// Check the post type of the id that is set as the front page.
$front_page_post_type = get_post_type($q->get("page_id"));
//Stop redirect to the single post.
$q->set('post_type', $front_page_post_type);
// Use the single post template (single.php) instead of page.php
// front-page.php still works with this to overwrite either.
if ($front_page_post_type != "page") {
$q->is_single = true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment