<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>WordPress Customizer Archives - rweber.net</title>
	<atom:link href="https://www.rweber.net/tag/customizer/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.rweber.net/tag/customizer/</link>
	<description>trying to be a mile wide AND a mile deep</description>
	<lastBuildDate>Sat, 16 Dec 2017 02:09:55 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
<site xmlns="com-wordpress:feed-additions:1">37896774</site>	<item>
		<title>WordPress Customizer resources</title>
		<link>https://www.rweber.net/javascript/wordpress-customizer-resources/</link>
					<comments>https://www.rweber.net/javascript/wordpress-customizer-resources/#respond</comments>
		
		<dc:creator><![CDATA[Rebecca]]></dc:creator>
		<pubDate>Mon, 21 Mar 2016 12:00:21 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP and MySQL]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Customizer]]></category>
		<category><![CDATA[WordPress theming]]></category>
		<guid isPermaLink="false">http://www.rweber.net/?p=39544</guid>

					<description><![CDATA[<div><img width="199" height="300" src="https://www.rweber.net/wp-content/uploads/2016/03/books-684594_1280-199x300.jpg" class="attachment-medium size-medium wp-post-image" alt="photo looking down a library aisle" style="float:left; margin-right:16px; margin-bottom:16px;" decoding="async" fetchpriority="high" srcset="https://www.rweber.net/wp-content/uploads/2016/03/books-684594_1280-199x300.jpg 199w, https://www.rweber.net/wp-content/uploads/2016/03/books-684594_1280-768x1158.jpg 768w, https://www.rweber.net/wp-content/uploads/2016/03/books-684594_1280.jpg 679w, https://www.rweber.net/wp-content/uploads/2016/03/books-684594_1280-99x150.jpg 99w" sizes="(max-width: 199px) 100vw, 199px" /></div>
<p>Slowly gathered and thoroughly weeded links to tutorials and other resources for incorporating the WordPress Customizer into your own themes - both PHP and JavaScript.</p>
<p>The post <a href="https://www.rweber.net/javascript/wordpress-customizer-resources/">WordPress Customizer resources</a> appeared first on <a href="https://www.rweber.net">rweber.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div><img width="199" height="300" src="https://www.rweber.net/wp-content/uploads/2016/03/books-684594_1280-199x300.jpg" class="attachment-medium size-medium wp-post-image" alt="photo looking down a library aisle" style="float:left; margin-right:16px; margin-bottom:16px;" decoding="async" srcset="https://www.rweber.net/wp-content/uploads/2016/03/books-684594_1280-199x300.jpg 199w, https://www.rweber.net/wp-content/uploads/2016/03/books-684594_1280-768x1158.jpg 768w, https://www.rweber.net/wp-content/uploads/2016/03/books-684594_1280.jpg 679w, https://www.rweber.net/wp-content/uploads/2016/03/books-684594_1280-99x150.jpg 99w" sizes="(max-width: 199px) 100vw, 199px" /></div><p>I&#8217;ve spent a lot of time recently in the WordPress Customizer for this theme and a client theme, and have found it slow to locate helpful references and tutorials. Part of that was not learning until recently that you can put a single word in quotation marks to keep Google from helpfully trying other word forms and synonyms to get you more results (&#8220;custom&#8221; and &#8220;customize&#8221; are far from interchangeable with &#8220;Customizer&#8221; in this context, so <a href="http://searchresearch1.blogspot.com/2016/02/answer-how-to-find-compound-concepts.html">thank you SearchReSearch for the trick</a>), but some of it was a lack of good material.</p>
<p><em>On with the show&#8230;</em><br />
The fundamental source is the <a href="https://developer.wordpress.org/themes/advanced-topics/customizer-api/">Customizer page in the WordPress Developer Handbook</a>. What it covers it does well, but it is pretty cursory. In some ways I find the old <a href="https://codex.wordpress.org/Theme_Customization_API">Customizer information in the Codex</a> easier to read.</p>
<h3>Other General Tutorials and Examples</h3>
<p>WPShout is a reliable source for entry-level tutorials that aren&#8217;t shallow, and you may find their <a href="http://wpshout.com/making-themes-more-wysiwyg-with-the-wordpress-customizer/">Customizer introduction and overview</a> helpful.</p>
<p>Tom McFarlin wrote a tutorial series for WPTuts+ that is well-explained. You can find an <a href="https://tommcfarlin.com/wordpress-theme-customizer/">index for the WPTuts+ series</a> on his blog.</p>
<p>The WPTuts+ series is a few years old, as is this <a href="http://themefoundation.com/wordpress-theme-customizer/">Theme Foundation Customizer tutorial</a>, which moves a little faster but is a little more comprehensive. However, the basic syntax is largely unchanged.</p>
<p>There&#8217;s a <a href="http://www.noupe.com/wordpress/wordpress-theme-customizer-first-steps-95423.html">general introduction on Noupe</a> that covers some of the same ground, but in a different way and with some different inclusions.</p>
<p>Tom McFarlin has <a href="https://tommcfarlin.com/wordpress-theme-customizer-maintainability/">suggestions on organizing your code for maintainability</a> that will already be the case if you are working from <a href="http://underscores.me/">Underscores</a>.</p>
<p>Here are two WordPress themes on GitHub that use the Customizer and have authors who know a lot about the Customizer: <a href="https://github.com/justintadlock/hybrid-core/tree/dev/customize">Hybrid Core by Justin Tadlock</a>; <a href="https://github.com/chipbennett/oenology/blob/master/functions/options-customizer.php">Oenology by Chip Bennett</a>.</p>
<h3>Adding Custom Controls</h3>
<p>WordPress provides a number of control types: checkbox, radio button, select box, textarea, dropdown of pages, color picker, and media selector. You can add your own on top of these.</p>
<p>If you are adding controls, whether custom or built-in, the input needs sanitation; <a href="http://themeshaper.com/2013/04/29/validation-sanitization-in-customizer/">ThemeShaper has an article on validation and sanitation</a> for the Customizer.</p>
<p><a href="http://ottopress.com/2012/making-a-custom-control-for-the-theme-customizer/">Otto has a good introduction to custom controls</a> that is a little old but still relevant.</p>
<p><a href="https://premium.wpmudev.org/blog/creating-custom-controls-wordpress-theme-customizer/">WPMU DEV has another intro, including the built-in controls</a>, that might be good for a second explanation.</p>
<p><a href="http://justintadlock.com/archives/2015/06/04/customizer-radio-image-control">Justin Tadlock has a tutorial on a control that replaces radio buttons with images</a> but still acts as a radio button control.</p>
<p>I found it easiest to understand custom controls via example. There are lots of collections of premade custom controls on GitHub that you can use and learn from, with a variety of authors: <a href="https://github.com/WPTRT/code-examples/tree/master/customizer">the WordPress Theme Review Team</a>, <a href="https://github.com/paulund/wordpress-theme-customizer-custom-controls">Paul Underwood</a>, and <a href="https://github.com/bueltge/Wordpress-Theme-Customizer-Custom-Controls">Frank B&uuml;ltge</a> for three (but see <a href="https://www.rweber.net/web-development/wordpress/learn-by-doing-wordpress-customizer/#custom-control">last week&#8217;s post</a> for a caveat). Braad Martin has a control for a <a href="https://github.com/BraadMartin/components/tree/master/customizer/alpha-color-picker">color picker with alpha</a>. You can also see custom controls in action in the <a href="https://github.com/xwp/wp-customize-posts">WP Customize Posts plugin by Weston Ruter</a>.</p>
<h3>Contextual Controls and Partial Preview Refresh</h3>
<p>Contextual controls are those that appear and disappear based on what you&#8217;re previewing or what choices you&#8217;ve made in other controls. It and partial refresh are frequently covered in the same articles so I grouped them together. I discuss both in <a href="https://www.rweber.net/web-development/wordpress/learn-by-doing-wordpress-customizer/">last week&#8217;s post</a>, for one.</p>
<p><a href="http://ottopress.com/2015/whats-new-with-the-customizer/">Otto talks about active_callback for contextual controls</a> in a post about recent changes to the Customizer as of May, 2015.</p>
<p>In a Stack Exchange answer, <a href="http://wordpress.stackexchange.com/questions/211779/customiser-active-callback-not-working-on-control-with-postmessage-transport/211953#211953">Weston Ruter discusses the JavaScript alternative to active_callback</a>.</p>
<p><a href="http://wpshout.com/polishing-the-wordpress-customizer-experience/">WPShout covers partial refresh and active_callback</a> in their follow-up to the general tutorial.</p>
<h3>The Future: More JavaScript, Less PHP</h3>
<p>Right now you can avoid JavaScript entirely provided you don&#8217;t mind the entire preview refreshing to update and you don&#8217;t want to hide and show controls dynamically. Since WordPress is great about back-compatibility, that probably will always be true. However, the future of the Customizer is in JavaScript. [Since the Customizer is pointless without JavaScript even my progressive-enhancement-obsessed soul can&#8217;t object.] Here are four links about using JavaScript for everything:</p>
<p><a href="https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/">Weston Ruter in Make WordPress Core</a> on how things work and where they&#8217;re going, October 2014.</p>
<p><a href="https://make.wordpress.org/core/2014/11/17/jsunderscore-template-rendered-custom-customizer-controls-in-wordpress-4-1/">Nick Halsey also in Make WordPress Core</a> on rendering custom controls with JavaScript, in particular; November 2014.</p>
<p>Justin Tadlock has also written about <a href="http://justintadlock.com/archives/2015/06/05/javascript-templating-in-the-wordpress-customizer">rendering custom controls with JavaScript</a>.</p>
<p>Finally, if you have a lot of options in the Customizer (the wisdom of that may be debatable) and they are injected with JavaScript, you may find your script is noticeably laggy. Here&#8217;s an article by Layers on <a href="http://www.layerswp.com/2015/07/how-to-speed-up-the-wordpress-customizer/">speeding up the Customizer via delayed loading of controls</a>.</p>
<p>I haven&#8217;t tried to implement a JavaScript-only Customizer in Amalgamation yet, but it&#8217;s on the list.</p>
<p>The post <a href="https://www.rweber.net/javascript/wordpress-customizer-resources/">WordPress Customizer resources</a> appeared first on <a href="https://www.rweber.net">rweber.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.rweber.net/javascript/wordpress-customizer-resources/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">39544</post-id>	</item>
		<item>
		<title>Learn by doing: the WordPress Customizer</title>
		<link>https://www.rweber.net/javascript/learn-by-doing-wordpress-customizer/</link>
					<comments>https://www.rweber.net/javascript/learn-by-doing-wordpress-customizer/#respond</comments>
		
		<dc:creator><![CDATA[Rebecca]]></dc:creator>
		<pubDate>Mon, 14 Mar 2016 12:00:22 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PHP and MySQL]]></category>
		<category><![CDATA[portfolio]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Customizer]]></category>
		<category><![CDATA[WordPress theming]]></category>
		<guid isPermaLink="false">http://www.rweber.net/?p=39529</guid>

					<description><![CDATA[<div><img width="300" height="214" src="https://www.rweber.net/wp-content/uploads/2016/03/TheaterFigurenMuseum_85-300x214.jpg" class="attachment-medium size-medium wp-post-image" alt="Marionettes in a museum by Jürgen Howaldt via Wikimedia Commons" style="float:left; margin-right:16px; margin-bottom:16px;" decoding="async" srcset="https://www.rweber.net/wp-content/uploads/2016/03/TheaterFigurenMuseum_85-300x214.jpg 300w, https://www.rweber.net/wp-content/uploads/2016/03/TheaterFigurenMuseum_85-150x107.jpg 150w, https://www.rweber.net/wp-content/uploads/2016/03/TheaterFigurenMuseum_85.jpg 512w" sizes="(max-width: 300px) 100vw, 300px" /></div>
<p>My experience incorporating the WordPress Customizer into my theme Amalgamation; notes and things to watch out for on both the PHP and the JavaScript sides.</p>
<p>The post <a href="https://www.rweber.net/javascript/learn-by-doing-wordpress-customizer/">Learn by doing: the WordPress Customizer</a> appeared first on <a href="https://www.rweber.net">rweber.net</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div><img width="300" height="214" src="https://www.rweber.net/wp-content/uploads/2016/03/TheaterFigurenMuseum_85-300x214.jpg" class="attachment-medium size-medium wp-post-image" alt="Marionettes in a museum by Jürgen Howaldt via Wikimedia Commons" style="float:left; margin-right:16px; margin-bottom:16px;" decoding="async" loading="lazy" srcset="https://www.rweber.net/wp-content/uploads/2016/03/TheaterFigurenMuseum_85-300x214.jpg 300w, https://www.rweber.net/wp-content/uploads/2016/03/TheaterFigurenMuseum_85-150x107.jpg 150w, https://www.rweber.net/wp-content/uploads/2016/03/TheaterFigurenMuseum_85.jpg 512w" sizes="auto, (max-width: 300px) 100vw, 300px" /></div><p>After the basics were in place, I started adding to Amalgamation (this site&#8217;s theme) to make it customizable for someone who might want, say, different pages featured in the front page&#8217;s panels. The correct place to put appearance-affecting settings is now the Customizer, which meant a lot of new learning.</p>
<p>It was not without its <s>swearing</s>difficulties, and for a while I had a nice little hack in place (labeled as such) but I got a handle on it and thought I&#8217;d write a bit about the parts that took me while to figure out or were difficult to find information on. This isn&#8217;t intended as a self-contained tutorial; I&#8217;ll follow this post up with a post of resources. <strong>Edit 3/12:</strong> The <a href="https://www.rweber.net/web-development/wordpress/wordpress-customizer-resources/">Customizer resource post</a> is up now.</p>
<h3>Customizer PHP</h3>
<p>In Amalgamation, this is all in <a href="https://github.com/ReveWeber/Amalgamation-WP-theme/blob/master/inc/customizer.php">customizer.php</a>.</p>
<p><a href="http://underscores.me/">Underscores</a> is a good start on the Customizer, especially for mimicking JavaScript syntax, but begins quite light on the PHP side. All it does is implement partial refresh for a few of the built-in settings. I wanted to add a bunch of new settings and also remove the irrelevant defaults, which you can see near the beginning of <code>amalgamation_customize_register()</code>.</p>
<p>There were two things I remember giving me pause when adding settings (<a href="http://pastebin.com/fdNX3AZ6">see code on Pastebin</a>):</p>
<p><script src="//pastebin.com/embed_js/fdNX3AZ6"></script></p>
<p>The first was keeping the pieces straight, including what needed the same name. The setup is a little convoluted; sections and controls are UI entities &#8211; they are about what appears and how in the Customizer pane. Settings are data entities &#8211; they hold the values you use controls within sections to select. That&#8217;s why they don&#8217;t exist within sections like controls do, and why the label and description are set within the control definition. They are, however, tightly coupled to controls, which is why they both get the same label as their first parameter.</p>
<p>The other mild slowdown was not knowing how to define a radio button selection, but hopefully my example makes it clear: in the choices array it is &#8216;setting&#8217;s value&#8217; => &#8216;value&#8217;s description&#8217;.</p>
<p><a id="custom-control"></a>WordPress has a page dropdown included, but I wanted to allow posts as well so I needed a custom control. I began by using a post select dropdown from <a href="https://github.com/paulund/wordpress-theme-customizer-custom-controls">Paul Underwood</a>, but changing the selection didn&#8217;t alert the Customizer that a change had been made &#8211; the Save button remained grayed out. Since I didn&#8217;t need the flexibility of that control I switched to one by <a href="https://github.com/tommusrhodus/">Tom Rhodes</a> that has since disappeared from his GitHub. That one worked, and I&#8217;ve since determined that the key was in the <code>select</code> element having the attribute <code>data-customize-setting-link="&lt;?php echo $this->id; ?&gt;"</code>. When I added that attribute to Paulund&#8217;s code, it worked as desired.</p>
<p>Note that the definition of the custom control needs to be accessible from within the function that&#8217;s adding the custom control. The easiest way to do that is to define it within the function, whether directly or via an include statement.</p>
<p>Using the settings in your theme is easy: <code>get_theme_mod( 'setting_name' );</code> returns (rather than echoes) the value.</p>
<h3>Customizer JavaScript</h3>
<p>This is in two files in Amalgamation: <a href="https://github.com/ReveWeber/Amalgamation-WP-theme/blob/master/js/customizer.js">customizer.js</a> and <a href="https://github.com/ReveWeber/Amalgamation-WP-theme/blob/master/js/customizer-controls.js">customizer-controls.js</a>; the enqueuings are in <a href="https://github.com/ReveWeber/Amalgamation-WP-theme/blob/master/inc/customizer.php">customizer.php</a>.</p>
<p>JavaScript is currently optional for the Customizer but developers are encouraged to use it for essentially all the functionality. I did not (though I intend to at least try it out in the future) but I made good use of JavaScript for dynamic display of controls in the sidebar and for partial refresh in the preview so a small change did not require the whole thing to reload.</p>
<p>The first thing to note is that there are two different actions to hook your script enqueue functions into, depending on whether the script affects the sidebar or the preview pane. The preview is in an iframe so it is effectively a completely separate website; scripts that live in one location can&#8217;t affect elements in the other.</p>
<p>For dynamic controls, the enqueue command is this (<a href="//pastebin.com/1gwtmpjm">view on Pastebin</a>):</p>
<p><script src="//pastebin.com/embed_js/1gwtmpjm"></script></p>
<p>You can code these as you would any other show/hide commands, but I found I needed to enclose them in an extra <code>$(function(){});</code> to delay execution and prevent them being overridden. The necessary ids for your elements will be generated following a standard pattern and are easy to find in the web inspector.</p>
<p>For preview AJAX, the enqueue command is this (<a href="//pastebin.com/hcfEsHLw">view on Pastebin</a>):</p>
<p><script src="//pastebin.com/embed_js/hcfEsHLw"></script></p>
<p>Note that I&#8217;m localizing the script also, as in <a href="https://www.rweber.net/web-development/wordpress/ajax-in-wp-a-simple-example/">my previous post about AJAX in WordPress</a>. This of course is only necessary if you actually plan to make AJAX calls. Within the script you have to follow the pattern</p>
<pre>wp.customize( 'setting_name', function (value) {
    value.bind(function (to) {
        // your css/html change or ajax call
    });
});</pre>
<p>If you leave out value.bind it won&#8217;t work. From what I understand, &#8220;value&#8221; here is the fact of the change, and &#8220;to&#8221; is the result or contents of the change (e.g. the color code, text of the byline, or id of the page you selected from the dropdown). Once you&#8217;re inside you can do whatever you want; it&#8217;s no different from JavaScript written from scratch to enact a change on the page. In particular <a href="https://www.rweber.net/web-development/wordpress/ajax-in-wp-a-simple-example/">AJAX works the same way as in WP at large</a>.</p>
<hr>
<p>There&#8217;s my contribution for now. Stay tuned for the resource post. <strong>Edit 3/21:</strong> <a href="https://www.rweber.net/web-development/wordpress/wordpress-customizer-resources/">My selection of customizer resources</a> is posted now.</p>
<p><small>Marionette photo by Jürgen Howaldt (Own work (selbst erstelltes Foto)) [<a href="http://creativecommons.org/licenses/by-sa/3.0/de/deed.en">CC BY-SA 3.0 de</a>], <a href="https://commons.wikimedia.org/wiki/File%3ATheaterFigurenMuseum_85.jpg">via Wikimedia Commons</a>.</small></p>
<p>The post <a href="https://www.rweber.net/javascript/learn-by-doing-wordpress-customizer/">Learn by doing: the WordPress Customizer</a> appeared first on <a href="https://www.rweber.net">rweber.net</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.rweber.net/javascript/learn-by-doing-wordpress-customizer/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">39529</post-id>	</item>
	</channel>
</rss>
