
Automatically Import Demos in a Child Theme – A Ready-Made Solution
Are you a WordPress theme designer or developer looking to sell your product? Perhaps you’ve already created a beautiful theme but are unsure how to provide an effortless setup experience for your users. This tutorial will walk you through a practical and automated way to let users import demos—including content, settings, and plugins—using only free tools.
What You’ll Need
- Your own base theme or child theme.
- Free plugins:
- One Click Demo Import
- Widget Importer & Exporter
- Customizer Export/Import
- A fully configured demo site with content and settings.
In this guide, I’ll use a pre-built VocePress child theme as an example. The full code is available for download, so you can customize it to fit your needs quickly.
What We Want to Achieve
Once your theme is installed, users should be able to:
- Install required plugins automatically.
- Import content (pages, posts, menus).
- Restore customizer settings (colors, fonts, headers).
- Re-import widgets (if applicable).
This allows users to get a fully functional replica of your demo site with minimal effort. Manually guiding users through these steps is not only time-consuming but also error-prone and unprofessional for premium products.
Let’s break down how to automate the entire process using free tools.
Step 1: Automatically Install Required Plugins
WordPress does not allow themes to bundle plugins directly. However, we can prompt users to install and activate them during setup.
We’ll use the TGM Plugin Activation library—a widely used solution for managing plugin dependencies in themes.
Add TGM to Your Child Theme
Place the following code in your functions.php
file:
/**
* Include the TGM_Plugin_Activation class.
*/
require_once get_stylesheet_directory() . '/libs/tgm-plugin-activation/class-tgm-plugin-activation.php';
add_action( 'tgmpa_register', 'vocepress_example_register_required_plugins' );
/**
* Register required plugins for this theme.
*/
function vocepress_example_register_required_plugins() {
$plugins = array(
// Example of bundled plugin
array(
'name' => 'Your External Plugin',
'slug' => 'your-external-plugin',
'source' => get_stylesheet_directory() . '/libs/tgm-plugin-activation/plugins/tgm-example-plugin.zip',
'required' => true,
),
// Plugin from the WordPress repository
array(
'name' => 'One Click Demo Import',
'slug' => 'one-click-demo-import',
'required' => true,
),
array(
'name' => 'Contact Form 7',
'slug' => 'contact-form-7',
'required' => false,
),
);
$config = array(
'id' => 'vocepress-example',
'default_path' => '',
'menu' => 'tgmpa-install-plugins',
'parent_slug' => 'themes.php',
'capability' => 'edit_theme_options',
'has_notices' => true,
'dismissable' => true,
'is_automatic' => false,
);
tgmpa( $plugins, $config );
}
This code adds support for both bundled plugins and those available in the WordPress Plugin Repository. Users will see a notice in the dashboard prompting them to install and activate the necessary plugins.
Step 2: Prepare Your Demo Content Files
Before you can import anything, you need to export the content and settings from your demo site.
Export WordPress Content
Go to Tools → Export, select “All content”, and generate an XML file. This will include pages, posts, media, and menu structures.
Example filename: demo-content.xml
.
Export Customizer Settings
Use the Customizer Export/Import plugin to export your theme’s appearance settings.
Navigate to Appearance → Customize → Export/Import, then click “Export”.
Example filename: customizer-export.dat
.
Export Widgets
Install the Widget Importer & Exporter plugin and go to Tools → Widget Importer & Exporter to export widget configurations.
Click the “Export Widgets” button and save the .wie
file.
Example filename: widgets.wie
.
Step 3: Configure One Click Demo Import
Now it’s time to set up the One Click Demo Import plugin to handle the full import process.
Define Import Files in functions.php
Add the following snippet to your theme’s functions.php
file:
function vocepress_example_import_files() {
return [
[
'import_file_name' => 'Demo Import 1',
'categories' => ['Category 1', 'Category 2'],
'import_file_url' => 'http://www.yourdomain.com/ocdi/demo-content.xml',
'import_widget_file_url' => 'http://www.yourdomain.com/ocdi/widgets.json',
'import_customizer_file_url' => 'http://www.yourdomain.com/ocdi/customizer.dat',
'import_preview_image_url' => 'http://www.yourdomain.com/ocdi/preview.jpg',
'preview_url' => 'http://www.yourdomain.com/my-demo-1',
],
[
'import_file_name' => 'Demo Import 2',
'categories' => ['New Category', 'Old Category'],
'import_file_url' => 'http://www.yourdomain.com/ocdi/demo-content2.xml',
'import_widget_file_url' => 'http://www.yourdomain.com/ocdi/widgets2.json',
'import_customizer_file_url' => 'http://www.yourdomain.com/ocdi/customizer2.dat',
'import_preview_image_url' => 'http://www.yourdomain.com/ocdi/preview2.jpg',
'preview_url' => 'http://www.yourdomain.com/my-demo-2',
]
];
}
add_filter( 'ocdi/import_files', 'vocepress_example_import_files' );
You can host the files on your server or CDN, and the plugin will fetch them when the user selects a demo.
Step 4: Automatically Set Up Front Page and Menus After Import
After importing the data, users usually still have to manually assign the front page and menu locations. Let’s automate that too.
Automatically Assign Static Front Page
function vocepress_example_after_import($selected_import) {
$home = get_page_by_title('News Magazine');
$blog = get_page_by_title('News');
if (isset($home->ID) && $home->ID > 0) {
update_option('page_on_front', $home->ID);
update_option('page_for_posts', $blog->ID);
update_option('show_on_front', 'page');
}
$primary_menu = get_term_by('name', 'Main Menu', 'nav_menu');
if (is_object($primary_menu)) {
set_theme_mod('nav_menu_locations', array(
'primary' => $primary_menu->term_id,
));
}
}
add_action('pt-ocdi/after_import', 'vocepress_example_after_import');
Make sure to replace "News Magazine"
, "News"
, and "Main Menu"
with the actual titles from your demo content.
Summary
With just a few lines of code added to your child theme, you can offer your users a seamless one-click demo import experience. This includes:
- Auto-installation of required plugins.
- Importing demo content (posts, pages, menus).
- Restoring customizer settings.
- Configuring homepage and navigation menus automatically.
This approach ensures your users don’t face manual configuration hurdles and can start customizing their new site right away.