Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Embracing the Customizer
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Luke Williams
February 21, 2013
Programming
810
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Embracing the Customizer
Luke Williams
February 21, 2013
More Decks by Luke Williams
See All by Luke Williams
Useful Mental Models For Product Engineers
redroot
0
160
Genetic Algorithms
redroot
0
95
Unity Talk
redroot
0
49
Neural Networks - a brief introduction by a fan
redroot
0
520
Web Accessibility in 2019
redroot
0
550
redux-saga
redroot
0
650
Redis - Lightning Talk @ RefME
redroot
0
800
Wordpress Multitenancy
redroot
0
1.5k
Other Decks in Programming
See All in Programming
AIで効率化できた業務・日常
ochtum
0
140
肥大化するレガシーコードに立ち向かうためのインターフェース分離と依存の逆転 / JJUG CCC 2026 Spring
hirokunimaeta
0
600
TAKTでAI駆動開発の品質を設計する
j5ik2o
7
1.5k
メソッドのジェネリクスでGoの夢は広がるか? / Kyoto.go #65
utgwkk
3
910
Webフレームワークの ベンチマークについて
yusukebe
0
180
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
3
730
AI時代のUIはどこへ行く?その2!
yusukebe
22
7.4k
AIだと陥りがちなJakarta EE最新技術への移行時の落とし穴と解決策
tnagao7
0
120
AIを活用したE2Eテスト実装効率化のあゆみ / ebisu-mobile-14-kotetu
kotetuco
0
130
Snowflake Summitでの新機能 CoCo / CoWork / snowflake-summit-2026-overall-what-new-coco
tatsuhiro
1
170
New "Type" system on PicoRuby
pocke
1
1k
エージェンティックRAGにAWSで入門しよう!
har1101
9
1.7k
Featured
See All Featured
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
62
55k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
400
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
140
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.5k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
780
Discover your Explorer Soul
emna__ayadi
2
1.1k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
240
Design in an AI World
tapps
1
250
How to train your dragon (web standard)
notwaldorf
97
6.7k
Mobile First: as difficult as doing things right
swwweet
225
10k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
230
Transcript
Embracing The Customizer @luke_redroot red-root.com
None
Then (April 2012)
Now
None
DEMO
Sections
Settings
Controls text text checkbox
# mytheme/functions.php require("lib/customizer.php"); # mytheme/lib/customizer.php add_action("customize_register",function($wpc){ // code here });
// PHP 5.3 add_action("customize_register",function($wpc){ // code here }); // equivalent
to add_action("customize_register","named_function"); function named_function($wpc){ // code here }
add_action("customize_register",function($wpc){ $wpc->add_section(); $wpc->add_setting(); $wpc->add_control(); });
$wpc->add_section("heading_section",array( "title" => "My Heading Section", "priority" => 35, "capability"
=> "edit_theme_options" ));
$wpc->add_setting("mytheme_options[heading]",array( "default" => "Default Heading", "type" => "option", "capability" =>
"edit_theme_options" ));
# mytheme/lib/customizer.php $wpc->add_setting("mytheme_options[heading]",array( "default" => "Default Heading", "type" => "option"
)); # mytheme/index.php $options = get_option("mytheme_options"); $heading = $options["heading"];
# mytheme/lib/customizer.php $wpc->add_setting("mytheme_options_heading",array( "default" => "Default Heading", "type" => "option",
)); # mytheme/index.php $heading = get_option("mytheme_options_heading");
# mytheme/lib/customizer.php $wpc->add_setting("heading",array( "default" => "Default Heading", "type" => "theme_mod"
)); # mytheme/index.php $heading = get_theme_mod("heading");
$wpc->add_control(“mytheme_options[heading]",array( "label" => "Custom Heading", "section" => "heading_section", "setting" =>
"mytheme_options[heading]", "type" => "text" ));
# text $wpc->add_control("mythemes_option[heading]",array( "label" => "Custom Heading", "section" => "heading_section",
"setting" => "mytheme_options[heading]", "type" => "text" )); # checkbox $wpc->add_control("mytheme_options[heading]",array( "label" => "A Checkbox", "section" => "heading_section", "setting" => "mytheme_options[heading]", "type" => "checkbox" ));
# select $wpc->add_control("mytheme_options[heading]",array( "label" => "A Checkbox", "section" => "heading_section",
"setting" => "mytheme_options[heading]", "type" => "select", "choices" => array( "value 1" => "text for 1", "value 2" => "text for 2" ) )); # radio $wpc->add_control("mytheme_options[heading]",array( "label" => "A Checkbox", "section" => "heading_section", "setting" => "mytheme_options[heading]", "type" => "radio", "choices" => array( "value 1" => "text for 1", "value 2" => "text for 2" ) ));
add_action("customize_register",function ($wpc){ $wpc->add_section("heading_section",array( "title" => "My Heading Section", "priority" =>
0 )); $wpc->add_setting("mytheme_options[heading]",array( "default" => "Default Heading", "type" => "option", "capability" => "edit_theme_options" )); $wpc->add_setting("mytheme_options[blue]",array( "default" => "false", "type" => "option", "capability" => "edit_theme_options" )); $wpc->add_setting("mytheme_options[subheading]",array( "default" => "Hot Fuzz", "type" => "option", "capability" => "edit_theme_options" )); $wpc->add_control("mytheme_options[heading]",array( "label" => "Custom Heading", "section" => "heading_section", "setting" => "mytheme_options[heading]", "type" => "text" )); $wpc->add_control("mytheme_options[blue]",array( "label" => "Make It Blue?", "section" => "heading_section", "setting" => "mytheme_options[blue]", "type" => "checkbox" )); $wpc->add_control("mytheme_options[subheading]",array( "label" => "subheading?", "section" => "heading_section", "setting" => "mytheme_options[subheading]", "type" => "select", "choices" => array( "Hot Fuzz" => "Hot Fuzz", "Shaun of the Dead" => "Shaun of the Dead", "The World Ends" => "The World Ends" ) )); });
# Remove default sections $wpc->remove_section("title_tagline"); $wpc->remove_section("static_front_page");
$colour_control = new WP_Customize_Color_Control( $wpc, 'mytheme_options[blue]', array( 'label' => "Heading
Color", 'section' => 'heading_section', 'settings' => 'mytheme_options[blue]', ) ); $wpc->add_control($colour_control);
$image_control = new WP_Customize_Image_Control( $wpc, 'mytheme_options[image]', array( 'label' => "Heading
Image", 'section' => 'heading_section', 'settings' => 'mytheme_options[image]', ) ); $wpc->add_control($image_control);
class WP_Customize_Category_Control extends WP_Customize_Control { public $type = 'dropdown-category'; public
function render_content() { $dropdown = wp_dropdown_categories(array( "selected" => $this->value(), "name" => $this->settings["default"]->id, "echo" => 0 )); $dropdown = str_replace( '<select', '<select '.$this->get_link(), $dropdown); ?> <label> <p class="customize-control-title"><?php echo esc_html($this->label);?></p> <div> <?php echo $dropdown; ?> </div> </label> <?php } } gist.github.com/redroot/4997131
# use postMessage transport $wpc->add_setting("mytheme_options[heading]",array( "default" => "Default Heading", "type"
=> "option", "capability" => "edit_theme_options", "transport" => "postMessage" ));
# mytheme/lib/customizer.php if($wpc->is_preview() && !is_admin()){ add_action("wp_footer", function(){ get_template_part("lib/views/customize_preview_js.php"); }); }
# mytheme/lib/views/customizer_previews_js.php <script> (function($){ wp.customize('mytheme_options[heading]',function(value){ value.bind(function(to){ $('h1').html(to); }); }); })(jQuery); </script>
CORESITES
Resources: https://github.com/redroot/wp-customizer-example http://ottopress.com/2012/how-to-leverage-the-theme-customizer-in- your-own-themes/ http://ottopress.com/2012/theme-customizer-part-deux-getting-rid-of- options-pages/ http://ottopress.com/2012/making-a-custom-control-for-the-theme- customizer/ https://codex.wordpress.org/Theme_Customization_API
Thanks! @luke_redroot red-root.com