{"id":4077,"date":"2016-09-30T07:37:14","date_gmt":"2016-09-30T04:37:14","guid":{"rendered":"http:\/\/vitaliykiyko.com\/?p=4077"},"modified":"2016-09-30T07:37:14","modified_gmt":"2016-09-30T04:37:14","slug":"fire-custom-js-code-wp-customizer-selective-refresh-made","status":"publish","type":"post","link":"https:\/\/vitaliykiyko.com\/en\/4077\/fire-custom-js-code-wp-customizer-selective-refresh-made\/","title":{"rendered":"Fire custom js code after WP Customizer selective refresh has been made"},"content":{"rendered":"Here the question: how to hook in custom code (function) just after selective refresh has been made?<\/p>\n<p>Luckely, the developers of WP have added several events which are trigger in certain moments of work of this relatively new feature of WP Customizer. They are:<\/p>\n<p>Events (triggered on wp.customize.selectiveRefresh):<\/p>\n<ul>\n<li>render-partials-response<\/li>\n<li>partial-content-rendered<\/li>\n<li>partial-placement-moved<\/li>\n<li>widget-updated<\/li>\n<li>sidebar-updated<\/li>\n<\/ul>\n<p>I needed precisely <code>partial-content-rendered<\/code> event, so this is a code I used (with the check of what exactly part of the content was rendered):<\/p>\n<pre>\r\nwp.customize.selectiveRefresh.bind( 'partial-content-rendered', function( placement ) {\r\n  if ( placement.partial.id === '...id of the customizer setting...' ) {\r\n    console.log('do smth!'); \/\/ add your code here!\r\n  }\r\n} );\r\n<\/pre>\n<p>Of course, it is required to add this code into the file that will be enqueued when Customizer is being loaded.","protected":false},"excerpt":{"rendered":"<p>Here the question: how to hook in custom code (function) just after selective refresh has been made? Luckely, the developers of WP have added several events which are trigger in certain moments of work of this relatively new feature of&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48],"tags":[],"_links":{"self":[{"href":"https:\/\/vitaliykiyko.com\/en\/wp-json\/wp\/v2\/posts\/4077"}],"collection":[{"href":"https:\/\/vitaliykiyko.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vitaliykiyko.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vitaliykiyko.com\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/vitaliykiyko.com\/en\/wp-json\/wp\/v2\/comments?post=4077"}],"version-history":[{"count":1,"href":"https:\/\/vitaliykiyko.com\/en\/wp-json\/wp\/v2\/posts\/4077\/revisions"}],"predecessor-version":[{"id":4078,"href":"https:\/\/vitaliykiyko.com\/en\/wp-json\/wp\/v2\/posts\/4077\/revisions\/4078"}],"wp:attachment":[{"href":"https:\/\/vitaliykiyko.com\/en\/wp-json\/wp\/v2\/media?parent=4077"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vitaliykiyko.com\/en\/wp-json\/wp\/v2\/categories?post=4077"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vitaliykiyko.com\/en\/wp-json\/wp\/v2\/tags?post=4077"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}