-
-
Save papacasper/4249ba15f3936a531ffd157e4f61a070 to your computer and use it in GitHub Desktop.
Customizer Tutorial
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
| $wp_customize->add_section( 'cd_colors' , array( | |
| 'title' => 'Colors', | |
| 'priority' => 30, | |
| ) ); |
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
| wp.customize( 'blogname', function( value ) { | |
| value.bind( function( newval ) { | |
| $( '#intro h1' ).html( newval ); | |
| } ); | |
| } ); | |
| wp.customize( 'blogdescription', function( value ) { | |
| value.bind( function( newval ) { | |
| $( '#intro h2' ).html( newval ); | |
| } ); | |
| } ); |
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
| $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'background_color', array( | |
| 'label' => 'Background Color', | |
| 'section' => 'cd_colors', | |
| 'settings' => 'background_color', | |
| ) ) ); |
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
| $wp_customize->add_setting( 'background_color' , array( | |
| 'default' => '#43C6E4', | |
| 'transport' => 'refresh', | |
| ) ); |
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
| add_action( 'wp_head', 'cd_customizer_css'); | |
| function cd_customizer_css() | |
| { | |
| ?> | |
| <style type="text/css"> | |
| body { background: #<?php echo get_theme_mod('background_color', '#43C6E4'); ?>; } | |
| </style> | |
| <?php | |
| } |
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
| ( function( $ ) { | |
| } )( jQuery ); |
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
| add_action( 'customize_register', 'cd_customizer_settings' ); | |
| function cd_customizer_settings( $wp_customize ) { | |
| } |
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
| ( function( $ ) { | |
| wp.customize( 'background_color', function( value ) { | |
| value.bind( function( newval ) { | |
| $( 'body' ).css( 'background-color', newval ); | |
| } ); | |
| } ); | |
| } )( jQuery ); |
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
| $wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; | |
| $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; |
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
| add_action( 'customize_preview_init', 'cd_customizer' ); | |
| function cd_customizer() { | |
| wp_enqueue_script( | |
| 'cd_customizer', | |
| get_template_directory_uri() . '/customizer.js', | |
| array( 'jquery','customize-preview' ), | |
| '', | |
| true | |
| ); | |
| } |
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
| include('customizer.php'); |
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
| function cd_show_main_button() { | |
| if( get_theme_mod( 'cd_button_display', 'show' ) == 'show' ) { | |
| echo "<a href='' class='button'>" . get_theme_mod( 'cd_button_text', 'Come On In' ) . "</a>"; | |
| } | |
| } |
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
| <div id='photocount'> | |
| <span><?php echo get_theme_mod( 'cd_photocount', 0 ) ?></span> photos | |
| </div> |
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
| $wp_customize->add_setting( 'cd_photocount' , array( | |
| 'default' => 0, | |
| 'transport' => 'postMessage', | |
| ) ); | |
| $wp_customize->add_control( new WP_Customize_Range( $wp_customize, 'cd_photocount', array( | |
| 'label' => 'Photo Count', | |
| 'min' => 10, | |
| 'max' => 9999, | |
| 'step' => 10, | |
| 'section' => 'title_tagline', | |
| ) ) ); |
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
| wp.customize( 'cd_photocount', function( value ) { | |
| value.bind( function( newval ) { | |
| $( '#photocount span' ).html( newval ); | |
| } ); | |
| } ); |
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
| if( class_exists( 'WP_Customize_Control' ) ) { | |
| class WP_Customize_Range extends WP_Customize_Control { | |
| public $type = 'range'; | |
| public function __construct( $manager, $id, $args = array() ) { | |
| parent::__construct( $manager, $id, $args ); | |
| $defaults = array( | |
| 'min' => 0, | |
| 'max' => 10, | |
| 'step' => 1 | |
| ); | |
| $args = wp_parse_args( $args, $defaults ); | |
| $this->min = $args['min']; | |
| $this->max = $args['max']; | |
| $this->step = $args['step']; | |
| } | |
| public function render_content() { | |
| ?> | |
| <label> | |
| <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> | |
| <input class='range-slider' min="<?php echo $this->min ?>" max="<?php echo $this->max ?>" step="<?php echo $this->step ?>" type='range' <?php $this->link(); ?> value="<?php echo esc_attr( $this->value() ); ?>" oninput="jQuery(this).next('input').val( jQuery(this).val() )"> | |
| <input onKeyUp="jQuery(this).prev('input').val( jQuery(this).val() )" type='text' value='<?php echo esc_attr( $this->value() ); ?>'> | |
| </label> | |
| <?php | |
| } | |
| } | |
| } |
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
| $wp_customize->selective_refresh->add_partial( 'cd_button_display', array( | |
| 'selector' => '#button-container', | |
| 'render_callback' => 'cd_show_main_button', | |
| ) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment