Skip to content

Instantly share code, notes, and snippets.

@alegut
Last active August 30, 2018 08:40
Show Gist options
  • Select an option

  • Save alegut/0d892c0b53d3f7f12b46efb2b67ba555 to your computer and use it in GitHub Desktop.

Select an option

Save alegut/0d892c0b53d3f7f12b46efb2b67ba555 to your computer and use it in GitHub Desktop.
How to add custom theme settings to WordPress
<?php
add_action('admin_menu', function () {
add_theme_page('Customizer', 'Customizer', 'edit_theme_options', 'customize.php');
});
add_action('customize_register', function ($customizer) {
$customizer->add_section(
'custom_setting',
array(
'title' => 'Custom Settings',
'description' => 'Description',
'priority' => 11,
)
);
$customizer->add_setting(
'company-phone',
array('default' => '000000000000')
);
$customizer->add_control(
'company-phone',
array(
'label' => 'Company phone',
'section' => 'custom_setting',
'type' => 'text',
)
);
$customizer->add_setting(
'company-email',
array('default' => '[email protected]')
);
$customizer->add_control(
'company-email',
array(
'label' => 'Company email',
'section' => 'custom_setting',
'type' => 'text',
)
);
$customizer->add_setting(
'company-address',
array('default' => 'Somewhere in Ukraine')
);
$customizer->add_control(
'company-address',
array(
'label' => 'Company address',
'section' => 'custom_setting',
'type' => 'text',
)
);
});
//Insert into page
get_theme_mod('company-address')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment