Skip to content

Instantly share code, notes, and snippets.

@andrewlaskey
Last active December 27, 2015 19:39
Show Gist options
  • Save andrewlaskey/7378872 to your computer and use it in GitHub Desktop.
Save andrewlaskey/7378872 to your computer and use it in GitHub Desktop.
Adding custom Wordpress theme options to customize page.
<?php
/**
* Taken from tutorial at http://ottopress.com/2012/theme-customizer-part-deux-getting-rid-of-options-pages/
* and http://ottopress.com/2012/making-a-custom-control-for-the-theme-customizer/
*/
add_action( 'customize_register', 'theme_customize_register' );
function theme_customize_register($wp_customize) {
//add a textarea control to the wp_customize
class Customize_Textarea_Control extends WP_Customize_Control {
public $type = 'textarea';
public function render_content() {
?>
<label>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<textarea rows="5" style="width:100%;" <?php $this->link(); ?>><?php echo esc_textarea( $this->value() ); ?></textarea>
</label>
<?php
}
}
//Social Links Section
$wp_customize->add_section( 'theme_social_links', array(
'title' => 'Social Links',
'priority' => 35,
) );
//LinkedIn Profile Url
$wp_customize->add_setting( 'linkedin_url', array(
'default' => '',
) );
$wp_customize->add_control( 'linkedin_url', array(
'label' => 'LinkedIn',
'section' => 'theme_social_links',
'type' => 'text',
) );
//Google+ Profile Url
$wp_customize->add_setting( 'googleplus_url', array(
'default' => '',
) );
$wp_customize->add_control( 'googleplus_url', array(
'label' => 'Google+',
'section' => 'theme_social_links',
'type' => 'text',
) );
//Twitter Profile Url
$wp_customize->add_setting( 'twitter_url', array(
'default' => '',
) );
$wp_customize->add_control( 'twitter_url', array(
'label' => 'Twitter',
'section' => 'theme_social_links',
'type' => 'text',
) );
//Address and Contact Section
$wp_customize->add_section( 'theme_contact', array(
'title' => 'Contact Info',
'priority' => 36,
) );
//Main Company Phone
$wp_customize->add_setting( 'company_phone', array(
'default' => '',
) );
$wp_customize->add_control( 'company_phone', array(
'label' => 'Company Phone',
'section' => 'theme_contact',
'type' => 'text',
) );
//Company Email
$wp_customize->add_setting( 'company_email', array(
'default' => '',
) );
$wp_customize->add_control( 'company_email', array(
'label' => 'Company Email',
'section' => 'theme_contact',
'type' => 'text',
) );
//Company Address
$wp_customize->add_setting( 'company_address', array(
'default' => '',
) );
$wp_customize->add_control( new Customize_Textarea_Control( $wp_customize, 'company_address', array(
'label' => 'Address',
'section' => 'theme_contact',
'settings' => 'company_address',
) ) );
}
?>
<a class="button button--social" href="<?php echo get_theme_mod( 'linkedin_url', 'default_value' ); ?>" title="LinkedIn Profile">LinkedIn Profile</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment