2

I have a page template called template-frontpage.php and I want to show it on front in customizer using new WordPress feature called starter content, following is my code:

add_action('after_setup_theme', function () {
    add_theme_support( 'starter-content', array(
        'posts' => array(
            'home' => array(
                // Use a page template with the predefined about page
                'template' => 'template-frontpage.php',
            ),
        ),
        'options' => array(
            'show_on_front' => 'page',
            'page_on_front' => 'home',
        ),
    ));
});
4
  • It is not working, front page is not set to home with page template template-frontpage.php Feb 11 '17 at 8:19
  • The template is not assigneetd, the page is not set for home or both? Please, edit the question and explain the problem you have.
    – cybmeta
    Feb 11 '17 at 8:21
  • page is not set and template is also not assigned. Feb 11 '17 at 8:24
  • starter-content only works on fresh installs, have you verified that?. See my answer.
    – cybmeta
    Feb 11 '17 at 9:53
2

The reference to a post needs the item symbol within double curly braces:

add_action('after_setup_theme', function () {
    add_theme_support( 'starter-content', array(
        'posts' => array(
            'home' => array(
                // Use a page template with the predefined about page
                'template' => 'template-frontpage.php',
            ),
        ),
        'options' => array(
            'show_on_front' => 'page',
            'page_on_front' => '{{home}}',
        ),
    ));
});

And remember: currently, starter-content works only on "fresh sites", that is new installs that have not yet had any posts, pages, widgets, or customizer settings updated. This state is indicated in the fresh_site option with a value of 1; if this option is 0, you can set it back to 1 and starter-content will work in a non-fresh site as well. It is planned to allow starter content for non-fresh site in future release (thanks @weston-ruter).

5
  • 2
    Note that at some point core should support applying starter content to non-fresh sites. See core.trac.wordpress.org/ticket/38624 Feb 11 '17 at 18:02
  • Good catch, I didn't know.
    – cybmeta
    Feb 11 '17 at 18:31
  • Amazing It works, I didn't knew about curly braces. Feb 12 '17 at 12:28
  • It would be so relief if starter content start showing on non-fresh site because right know I'm developing a theme and every time I have to create new WordPress website on localhost for testing :( Feb 12 '17 at 12:29
  • 2
    You can set fresh_site option to 1 (update_option( 'fresh_site', 1 )) and starter content will be workgin again.
    – cybmeta
    Feb 13 '17 at 7:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.