The get_theme_starter_content WordPress PHP filter allows you to modify the default starter content provided by a theme.
Usage
add_filter('get_theme_starter_content', 'my_custom_starter_content', 10, 2);
function my_custom_starter_content($content, $config) {
// your custom code here
return $content;
}
Parameters
- $content (array) – An array of the existing starter content.
- $config (array) – An array of theme-specific starter content configuration.
More information
See WordPress Developer Resources: get_theme_starter_content
Examples
Adding a new page
Add a new “About Us” page to the starter content.
add_filter('get_theme_starter_content', 'add_about_us_page', 10, 2);
function add_about_us_page($content, $config) {
$content['pages']['about_us'] = array(
'post_type' => 'page',
'post_title' => __('About Us', 'my_theme'),
);
return $content;
}
Modifying the home page content
Update the home page title and content.
add_filter('get_theme_starter_content', 'update_home_page_content', 10, 2);
function update_home_page_content($content, $config) {
$content['pages']['home']['post_title'] = __('Welcome to My Site', 'my_theme');
$content['pages']['home']['post_content'] = __('This is the new home page content.', 'my_theme');
return $content;
}
Adding a custom menu
Add a custom menu with two links.
add_filter('get_theme_starter_content', 'add_custom_menu', 10, 2);
function add_custom_menu($content, $config) {
$content['nav_menus']['custom'] = array(
'name' => __('Custom Menu', 'my_theme'),
'items' => array(
'link_home' => array(
'type' => 'custom',
'title' => __('Home', 'my_theme'),
'url' => home_url('/'),
),
'link_about' => array(
'type' => 'post_type',
'object' => 'page',
'object_id' => '{{about_us}}',
),
),
);
return $content;
}
Removing a widget
Remove the search widget from the starter content.
add_filter('get_theme_starter_content', 'remove_search_widget', 10, 2);
function remove_search_widget($content, $config) {
unset($content['widgets']['search']);
return $content;
}
Adding a custom logo
Add a custom logo to the starter content.
add_filter('get_theme_starter_content', 'add_custom_logo', 10, 2);
function add_custom_logo($content, $config) {
$content['attachments']['custom_logo'] = array(
'file' => 'path/to/custom-logo.png',
'post_title' => __('Custom Logo', 'my_theme'),
);
$content['options']['custom_logo'] = '{{custom_logo}}';
return $content;
}