0

I recently started working on a WordPress theme and found this utility. I'm currently using WordPress 4.7.4. I've made following modifications to my code,

In FUNCTION.PHP;

function mytheme_setup(){
    register_nav_menus( array(
    'side'    => __( 'Side Menu', 'mytheme' ),
    'social' => __( 'Social Links Menu', 'mytheme' ),
    ) );

    $starter_content = array(
    // Set up nav menus for each of the two areas registered in the theme.
    'nav_menu'  =>  array(
        // Assign a menu to the "side" location.
        'side'  =>  array(
            'name'  =>  __( 'Side Menu', 'mytheme' ),
            'items' =>  array(
                'link_recent'   =>  array(
                    'title' =>  _x( 'Recent Articles', 'Theme starter content' ),
                    'url'   =>  site_url( '/#recent-articles' ),
                ),
                'link_about'    =>  array(
                    'title' =>  _x( 'About Us', 'Theme starter content' ),
                    'url'   =>  site_url( '/#about-us' ),
                ),
                'link_contact'  =>  array(
                    'title' =>  _x( 'Contact', 'Theme starter content' ),
                    'url'   =>  site_url( '/#contact-us' ),
                ),
            ),
        ),

        // Assign a menu to the "social" location.
        'social' => array(
            'name' => __( 'Social Links Menu', 'mytheme' ),
            'items' => array(
                'link_facebook',
                'link_twitter',
                'link_instagram',
                'link_youtube',
            ),
        ),
    ),
    );

    $starter_content = apply_filters( 'mytheme_starter_content', $starter_content );

    add_theme_support('starter-content', $starter_content);
}
add_action( 'after_setup_theme', 'mytheme_setup' );

And, in FRONT-PAGE.PHP,

    <?php if ( has_nav_menu( 'side' ) ) : ?>
        <div class="navigation-side">

            <nav id="site-navigation" class="main-navigation" role="navigation">
            <?php
             wp_nav_menu( array(
                 'theme_location'    =>  'side',
             ));
             ?>
            </nav>

        </div><!-- .navigation-side -->
    <?php endif; ?>

But still, I can't find any starter content menus on my theme.

1 Answer 1

2

I think you've a typo here:

'nav_menu'  =>  array(

Replace it with:

'nav_menus'  =>  array(

We can also check out how it's setup in the default Twenty Seventeen theme and look further how it's implemented within get_theme_starter_content():

// And nav menu items are grouped into nav menus.
case 'nav_menus' :
    foreach ( $config[ $type ] as $nav_menu_location => $nav_menu ) {

        // Ensure nav menus get a name.
        if ( empty( $nav_menu['name'] ) ) {
            $nav_menu['name'] = $nav_menu_location;
        }

        $content[ $type ][ $nav_menu_location ]['name'] = $nav_menu['name'];

        foreach ( $nav_menu['items'] as $id => $nav_menu_item ) {
            if ( is_array( $nav_menu_item ) ) {

                // Item extends core content.
                if ( ! empty( $core_content[ $type ][ $id ] ) ) {
                    $nav_menu_item = array_merge( $core_content[ $type ][ $id ], $nav_menu_item );
                }

                $content[ $type ][ $nav_menu_location ]['items'][] = $nav_menu_item;
            } elseif ( is_string( $nav_menu_item ) && ! empty( $core_content[ $type ] ) && ! empty( $core_content[ $type ][ $nav_menu_item ] ) ) {
                $content[ $type ][ $nav_menu_location ]['items'][] = $core_content[ $type ][ $nav_menu_item ];
            }
        }
    }
    break;

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.