SlideShare a Scribd company logo
WordPress Customizer
wordpress 3.4 — theme customizer
WordPress Customizer
WordPress Customizer
WordPress Customizer
WordPress Customizer
function _sj_customize_register( $wp_customize ) { 
$wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; 
$wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; 
$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; 
/* ... */ 
} 
add_action( 'customize_register', '_sj_customize_register' ); 
/** 
* Binds JS handlers to make Theme Customizer preview reload changes asynchronously. 
*/ 
function _sj_customize_preview_js() { 
wp_enqueue_script( '_sj_customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' 
), '', true ); 
} 
add_action( 'customize_preview_init', '_sj_customize_preview_js' );
$wp_customize->add_setting( 'sj_header_logo', array( 
'default' => get_template_directory_uri() . '/img/blog-logo.png', 
'transport' => 'postMessage' 
) );
$wp_customize->add_panel( 'sj_images', 
array( 
'title' => __( 'Images', '_sj' ), 
'priority' => 10 
) );
$wp_customize->add_section( 'header', array( 
'title' => __( 'Header', '_sj' ), 
'panel' => 'sj_images', 
'priority' => 10 
) );
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'sj_header_logo', array( 
'label' => __( 'Upload a header logo', '_sj' ), 
'section' => 'header' 
) ) );
( function( $ ) { 
// Header logo. 
wp.customize( 'sj_header_logo', function( value ) { 
value.bind( function( to ) { 
$( 'h1.title img' ).hide(); 
if ( to ) { 
$( 'h1.title img:not(.default)' ).attr( 'src', to ).show(); 
} 
else { 
$( 'h1.title img.default' ).show(); 
} 
} ); 
} ); 
} )( jQuery );
<?php 
$sj_header_logo_default = get_template_directory_uri() . '/base_html/img/blog-logo.png'; 
$sj_header_logo = get_theme_mod( 'sj_header_logo' ); 
if ( empty( $sj_header_logo ) ) 
$sj_header_logo = $sj_header_logo_default; 
?> 
<h1 class="title"> 
<a href="<?php echo esc_url( home_url( '/' ) ); ?>"> 
<img src="<?php echo $sj_header_logo; ?>" alt="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>" /> 
<?php if ( is_customize_preview() ) : ?> 
<img src="<?php echo $sj_header_logo_default; ?>" alt="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>" 
class="default" style="display: none" /> 
<?php endif; ?> 
</a> 
</h1>
WordPress Customizer
WordPress Customizer
WordPress Customizer
WordPress Customizer

More Related Content

KEY
JS for Rails developers
PDF
Crea un tema compatibile con le ultime novità WordPress
PDF
UI実装におけるコーディングあれこれ
PDF
Templating WordPress
KEY
jQuery Plugins Intro
PDF
Working With Ajax Frameworks
TXT
Formulario
PDF
Drupal 8. Movement towards. Susikov Sergey
JS for Rails developers
Crea un tema compatibile con le ultime novità WordPress
UI実装におけるコーディングあれこれ
Templating WordPress
jQuery Plugins Intro
Working With Ajax Frameworks
Formulario
Drupal 8. Movement towards. Susikov Sergey

What's hot (20)

PDF
もっと使いやすくなる a-blog cms の更新方法カスタマイズ
PPT
Tools20121015
PPTX
Concevoir un thème pour Wordpress
PDF
Як досвід компанії перетворився на фреймворк
PDF
Drupal Cms Prezentace
PPT
jQuery - Write less, do more!
PDF
Verbo POUPAR
PPT
Palestra sobre MongoDB com PHP no PHP'n'Rio
PDF
jQuery for beginners
PPTX
10 Programación Web con .NET y C#
PDF
ສ້າງລະບົບ Loin ດ້ວຍ php
TXT
Index2
PDF
Contes 66pdf
ODP
JavascriptMVC
PPTX
Advanced JQuery
PDF
Jquery overview 2013
KEY
jQuery入門
PDF
Web components copy
PDF
Bootcamp Google Abidjan 2012: Workshop Gaou Search
PDF
スマホウェブの本命 jQueryMobile
もっと使いやすくなる a-blog cms の更新方法カスタマイズ
Tools20121015
Concevoir un thème pour Wordpress
Як досвід компанії перетворився на фреймворк
Drupal Cms Prezentace
jQuery - Write less, do more!
Verbo POUPAR
Palestra sobre MongoDB com PHP no PHP'n'Rio
jQuery for beginners
10 Programación Web con .NET y C#
ສ້າງລະບົບ Loin ດ້ວຍ php
Index2
Contes 66pdf
JavascriptMVC
Advanced JQuery
Jquery overview 2013
jQuery入門
Web components copy
Bootcamp Google Abidjan 2012: Workshop Gaou Search
スマホウェブの本命 jQueryMobile
Ad

WordPress Customizer

  • 2. wordpress 3.4 — theme customizer
  • 7. function _sj_customize_register( $wp_customize ) { $wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; /* ... */ } add_action( 'customize_register', '_sj_customize_register' ); /** * Binds JS handlers to make Theme Customizer preview reload changes asynchronously. */ function _sj_customize_preview_js() { wp_enqueue_script( '_sj_customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '', true ); } add_action( 'customize_preview_init', '_sj_customize_preview_js' );
  • 8. $wp_customize->add_setting( 'sj_header_logo', array( 'default' => get_template_directory_uri() . '/img/blog-logo.png', 'transport' => 'postMessage' ) );
  • 9. $wp_customize->add_panel( 'sj_images', array( 'title' => __( 'Images', '_sj' ), 'priority' => 10 ) );
  • 10. $wp_customize->add_section( 'header', array( 'title' => __( 'Header', '_sj' ), 'panel' => 'sj_images', 'priority' => 10 ) );
  • 11. $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'sj_header_logo', array( 'label' => __( 'Upload a header logo', '_sj' ), 'section' => 'header' ) ) );
  • 12. ( function( $ ) { // Header logo. wp.customize( 'sj_header_logo', function( value ) { value.bind( function( to ) { $( 'h1.title img' ).hide(); if ( to ) { $( 'h1.title img:not(.default)' ).attr( 'src', to ).show(); } else { $( 'h1.title img.default' ).show(); } } ); } ); } )( jQuery );
  • 13. <?php $sj_header_logo_default = get_template_directory_uri() . '/base_html/img/blog-logo.png'; $sj_header_logo = get_theme_mod( 'sj_header_logo' ); if ( empty( $sj_header_logo ) ) $sj_header_logo = $sj_header_logo_default; ?> <h1 class="title"> <a href="<?php echo esc_url( home_url( '/' ) ); ?>"> <img src="<?php echo $sj_header_logo; ?>" alt="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>" /> <?php if ( is_customize_preview() ) : ?> <img src="<?php echo $sj_header_logo_default; ?>" alt="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>" class="default" style="display: none" /> <?php endif; ?> </a> </h1>