Last active
April 28, 2017 21:46
-
-
Save robgolbeck/86189e3a2d9799b0e669 to your computer and use it in GitHub Desktop.
WordPress Sample Theme Customizer
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 | |
// Now use the setting in your theme. | |
// (This example get's the logo). | |
if ( get_theme_mod( 'hc_logo' ) ) { ?> | |
<img src="<?php echo get_theme_mod( 'hc_logo', '' ); ?>" alt="<?php echo bloginfo('name'); ?>"> | |
<?php } else { ?> |
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 | |
// Sample Theme Customizer Options for WordPress | |
// This example allows you to upload your logo, add your contact info, and add your social media links. | |
// Reference: https://codex.wordpress.org/Theme_Customization_API | |
// See also: http://themefoundation.com/wordpress-theme-customizer/ | |
// Add the following to functions.php (or put it in a separate file - e.g. theme-customizer.php - and call it from functions.php) | |
new theme_customizer(); | |
class theme_customizer | |
{ | |
public function __construct() | |
{ | |
add_action( 'customize_register', array(&$this, 'hc_customize_manager' )); | |
} | |
public function hc_customize_manager( $wp_customize ) | |
{ | |
$this->demo_section( $wp_customize ); | |
} | |
public function demo_section( $wp_customize ) | |
{ | |
///////////////////////// | |
// Branding | |
///////////////////////// | |
$wp_customize->add_section( 'hc_branding_section', array( | |
'title' => 'Branding', | |
'priority' => 35, | |
) ); | |
// Logo | |
$wp_customize->add_setting( 'hc_logo', array( | |
'default' => '', | |
) ); | |
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'hc_logo', array( | |
'label' => 'Logo', | |
'description' => 'Upload your logo here.', | |
'section' => 'hc_branding_section', | |
'settings' => 'hc_logo', | |
'priority' => 1 | |
) ) ); | |
///////////////////////// | |
// Contact Info | |
///////////////////////// | |
$wp_customize->add_section( 'hc_contact_section', array( | |
'title' => 'Contact Info', | |
'priority' => 36, | |
) ); | |
// Street Address | |
$wp_customize->add_setting( 'contact_streetaddress', array( | |
'default' => '', | |
) ); | |
$wp_customize->add_control( 'contact_streetaddress', array( | |
'label' => 'Street Address', | |
'section' => 'hc_contact_section', | |
'type' => 'text_area', | |
'priority' => 1 | |
) ); | |
// City | |
$wp_customize->add_setting( 'contact_city', array( | |
'default' => '', | |
) ); | |
$wp_customize->add_control( 'contact_city', array( | |
'label' => 'City', | |
'section' => 'hc_contact_section', | |
'type' => 'text_area', | |
'priority' => 2 | |
) ); | |
// Province | |
$wp_customize->add_setting( 'contact_province', array( | |
'default' => '', | |
) ); | |
$wp_customize->add_control( 'contact_province', array( | |
'label' => 'Province', | |
'section' => 'hc_contact_section', | |
'type' => 'text_area', | |
'priority' => 3 | |
) ); | |
// Postal Code | |
$wp_customize->add_setting( 'contact_postalcode', array( | |
'default' => '', | |
) ); | |
$wp_customize->add_control( 'contact_postalcode', array( | |
'label' => 'Postal Code', | |
'section' => 'hc_contact_section', | |
'type' => 'text_area', | |
'priority' => 4 | |
) ); | |
// Phone Number | |
$wp_customize->add_setting( 'phone_number', array( | |
'default' => '', | |
) ); | |
$wp_customize->add_control( 'phone_number', array( | |
'label' => 'Phone Number', | |
'section' => 'hc_contact_section', | |
'type' => 'text_area', | |
'priority' => 5 | |
) ); | |
///////////////////////// | |
// Social Links | |
///////////////////////// | |
$wp_customize->add_section( 'hc_socialmedia_section', array( | |
'title' => 'Social Media', | |
'priority' => 37, | |
) ); | |
$wp_customize->add_setting( 'hc_twitter', array( | |
'default' => '', | |
) ); | |
$wp_customize->add_control( 'hc_twitter', array( | |
'label' => 'Twitter', | |
'description' => 'Enter the url for your Twitter profile here.', | |
'section' => 'hc_socialmedia_section', | |
'type' => 'text_area', | |
'priority' => 1 | |
) ); | |
$wp_customize->add_setting( 'hc_facebook', array( | |
'default' => '', | |
) ); | |
$wp_customize->add_control( 'hc_facebook', array( | |
'label' => 'Facebook', | |
'description' => 'Enter the url for your Facebook page or profile here.', | |
'section' => 'hc_socialmedia_section', | |
'type' => 'text_area', | |
'priority' => 2 | |
) ); | |
$wp_customize->add_setting( 'hc_linkedin', array( | |
'default' => '', | |
) ); | |
$wp_customize->add_control( 'hc_linkedin', array( | |
'label' => 'LinkedIn', | |
'description' => 'Enter the url for your LinkedIn profile.', | |
'section' => 'hc_socialmedia_section', | |
'type' => 'text_area', | |
'priority' => 3 | |
) ); | |
// Vimeo | |
$wp_customize->add_setting( 'hc_vimeo', array( | |
'default' => '', | |
) ); | |
$wp_customize->add_control( 'hc_vimeo', array( | |
'label' => 'Vimeo', | |
'description' => 'Enter the url for your Vimeo channel.', | |
'section' => 'hc_socialmedia_section', | |
'type' => 'text_area', | |
'priority' => 4 | |
) ); | |
$wp_customize->add_setting( 'hc_instagram', array( | |
'default' => '', | |
) ); | |
$wp_customize->add_control( 'hc_instagram', array( | |
'label' => 'Instagram', | |
'description' => 'Enter the url for your Instagram feed.', | |
'section' => 'hc_socialmedia_section', | |
'type' => 'text_area', | |
'priority' => 5 | |
) ); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment