Skip to content

Instantly share code, notes, and snippets.

@jsakas
Created September 19, 2019 04:45
Show Gist options
  • Save jsakas/03348bb81af0c5fc5549a5ae7477ddc2 to your computer and use it in GitHub Desktop.
Save jsakas/03348bb81af0c5fc5549a5ae7477ddc2 to your computer and use it in GitHub Desktop.

Wordpress: Custom page template with static home page

Wordpress ignores the selected page template for a page if you set it as a static home page, which is pretty frustrating in certain cases.

You can force it to use the custom page template by using this filter:

/**
 * Use selected page template for static home page
 */
add_filter('template_include', function ($template) {
    global $post;
    $page_template = get_page_template_slug($post->ID);
    if (is_front_page() && $page_template) {
        $new_template = locate_template($page_template);
        if ( ! empty($new_template)) {
            return $new_template;
        }
    }
    return $template;
}, 99);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment