Created
October 15, 2017 08:06
-
-
Save dr5hn/d3ddd5c7931b7818cc011b996f67aa2d to your computer and use it in GitHub Desktop.
How to add Custom Settings to Wordpress Appearance Customize Section
This file contains 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 | |
/** | |
* Custom Wordpress Customize Settings -- By Darshan Gada | |
* @param webgeeks (Replace webgeeks with your theme name) | |
* @function webgeeks_theme_options | |
*/ | |
function webgeeks_theme_options( $wp_customize ) { | |
//Sections, settings and controls will be added here | |
//Custom Setting for Header Logo Image | |
//Adding Section | |
$wp_customize->add_section( | |
'webgeeks_theme_settings', | |
array( | |
'title' => __('Webgeeks Theme Settings','webgeeks'), | |
'priority' => 100, | |
'capability' => 'edit_theme_options', | |
'description' => __('Change theme settings here.', 'webgeeks'), | |
) | |
); | |
//Adding Header Logo Settings | |
$wp_customize->add_setting('header_logo'); | |
//Adding Header Logo Control | |
$wp_customize->add_control( | |
new WP_Customize_Upload_Control($wp_customize, 'header_logo', | |
array( | |
'label' => __('Header Logo', 'webgeeks'), | |
'section' => 'webgeeks_theme_settings', | |
'settings' => 'header_logo', | |
) | |
) | |
); | |
//Custom Settings for Footer Logo | |
//Adding Footer Logo Settings | |
$wp_customize->add_setting('footer_logo'); | |
//Adding Footer Logo Control | |
$wp_customize->add_control( | |
new WP_Customize_Upload_Control($wp_customize, 'footer_logo', | |
array( | |
'label' => __('Footer Logo', 'webgeeks'), | |
'section' => 'webgeeks_theme_settings', | |
'settings' => 'footer_logo', | |
) | |
) | |
); | |
//Custom Settings for Footer Contact Section | |
//Adding Footer Contact Section Settings | |
$wp_customize->add_setting('footer_contact_address', | |
array( | |
'default' => 'Address' | |
) | |
); | |
//Adding Footer Contact Section Control | |
$wp_customize->add_control( | |
'footer_contact_address', | |
array( | |
'label' => 'Footer Contact Address', | |
'section' => 'webgeeks_theme_settings', | |
'type' => 'textarea', | |
'settings' => 'footer_contact_address', | |
) | |
); | |
} | |
//Applying function to Appearance>Customize Menu | |
add_action('customize_register', 'webgeeks_theme_options'); | |
//Set Default Theme Options to Variables | |
function update_theme_options() { | |
$header_logo = get_option('header_logo', get_stylesheet_directory_uri().'/assets/images/logo.png'); | |
$footer_logo = get_option('footer_logo', get_stylesheet_directory_uri().'/assets/images/big-logo.png'); | |
$footer_contact_address = get_option('footer_contact_address','Test'); | |
?> | |
<!-- Get User Customised Data and Inject it with Javascript inside Divs --> | |
<script type="text/javascript"> | |
jQuery(document).ready(function() { | |
jQuery('.logo').html(''); | |
jQuery('.logo').html('<img src="<?=$header_logo;?>" class="img-responsive"/>'); | |
jQuery('.footer-logo').html(''); | |
jQuery('.footer-logo').html('<img src="<?=$footer_logo;?>" class="img-responsive"/>'); | |
jQuery('.footer-text').html(''); | |
jQuery('.footer-text').html('<p>CONTACT US<br/><?=$footer_contact_address;?></p>'); | |
}); | |
</script> | |
<?php } add_action( 'wp_head', 'update_theme_options' ); ?>*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment