Last active
August 30, 2018 08:40
-
-
Save alegut/0d892c0b53d3f7f12b46efb2b67ba555 to your computer and use it in GitHub Desktop.
How to add custom theme settings to WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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