Let think you are WordPress theme developer and designer and you want use “One Click Demo Import” to import your theme demo contents.
There is just three simple steps to do the job.
Step One – Export Your Demo Data
First of all, export your demo website data by following plugins.
- Data Export: Go to “Tools -> Export” in WordPress Dashboard. Export all data with XML format.
- Widget Importer & Exporter: Install this plugin and export widgets with wie format.
- Customizer Export: Install this plugin and export customizations from Customize section with dat format.
Upload these files in your host or add them to your theme folder. The standard way is, uploading them to your own host.
Step Two – Functions.php Codes
Add the following codes to your theme’s functions.php file.
function hs_import_files()
{
return [
[
'import_file_name' => __('Theme Name', 'text-domain'),
'import_file_url' => 'http://your-website.com/content.xml',
'import_widget_file_url' => 'http://your-website.com/widgets.wie',
'import_customizer_file_url' => 'http://your-website.com/customizer.dat',
],
];
}
add_filter('ocdi/import_files', 'hs_import_files');
Step Three – Adjust Contents After Import
After import demo data sometimes you need adjust your theme like customization. Add the following code to the functions.php file.
function hs_ocdi_after_import_setup()
{
// Assign menus to their locations.
$main_menu = get_term_by('name', 'main menu', 'nav_menu');
$social_menu = get_term_by('name', 'social menu', 'nav_menu');
set_theme_mod(
'nav_menu_locations',
[
'main-menu' => $main_menu->term_id, // replace 'main-menu' here with the menu location identifier from register_nav_menu() function in your theme.
'social-menu' => $social_menu->term_id,
]
);
}
add_action('ocdi/after_import', 'hs_ocdi_after_import_setup');