Support » Plugin: One Click Demo Import » Assigning Menus After Import

  • Resolved ekaboom

    (@ekaboom)


    After looking at your FAQ for attaching menus after the import, I have a few questions about how to modify it:
    https://wordpress.org/plugins/one-click-demo-import/#how%20to%20automatically%20assign%20%E2%80%9Cfront%20page%E2%80%9D%2C%20%E2%80%9Cposts%20page%E2%80%9D%20and%20menu%20locations%20after%20the%20importer%20is%20done%3F

    I’ve added some comments to a version of this with multiple menus. Can you tell me if my comments are correct? (I’m not a programmer so sorry if I’m way off on anything)

    function ocdi_after_import_setup() {
        // Assign menus to their locations.
        $main_menu = get_term_by( 'name', 'Menu', 'nav_menu' );  // "$main_menu" is the function name and if changed, needs to be changed below.  'Menu' is what you've named your menu in the backend of wordpress.
    	$second_menu = get_term_by( 'name', 'Second', 'nav_menu' );  // if you add more change menus, create a new function name and add the wp backend name of the menu (i.e. 'Second').
        $menu_mobile = get_term_by( 'name', 'Mobile', 'nav_menu' );  // you can add additional menus if you have/use them.
    
        set_theme_mod( 'nav_menu_locations', array(  // don't change this
                'primary_menu' => $main_menu->term_id,  // in this case primary_menu is how your theme references a particular menu in your theme.  For $main_menu, match it with function name above.
    			'secondary_menu' => $second_menu->term_id,  // 'secondary_menu' is how the theme references a second menu in your theme.  $second_menu should match the function name above.
                'mobile_menu' => $menu_mobile->term_id,  //'mobile_menu' is how the theme references a mobile menu in your theme.  $menu_mobile should match the function name above.
            )
        );
    
        // Assign front page and posts page (blog page).
        $front_page_id = get_page_by_title( 'Home' );
        $blog_page_id  = get_page_by_title( 'Blog' );
    
        update_option( 'show_on_front', 'page' );
        update_option( 'page_on_front', $front_page_id->ID );
        update_option( 'page_for_posts', $blog_page_id->ID );
    
    }
    add_action( 'pt-ocdi/after_import', 'ocdi_after_import_setup' );
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Assigning Menus After Import’ is closed to new replies.