customizer.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * UIU CSE Theme Customizer
  4. *
  5. * @package UIU_CSE
  6. */
  7. /**
  8. * Add postMessage support for site title and description for the Theme Customizer.
  9. *
  10. * @param WP_Customize_Manager $wp_customize Theme Customizer object.
  11. */
  12. function uiu_cse_customize_register( $wp_customize ) {
  13. $wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
  14. $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
  15. $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
  16. if ( isset( $wp_customize->selective_refresh ) ) {
  17. $wp_customize->selective_refresh->add_partial(
  18. 'blogname',
  19. array(
  20. 'selector' => '.site-title a',
  21. 'render_callback' => 'uiu_cse_customize_partial_blogname',
  22. )
  23. );
  24. $wp_customize->selective_refresh->add_partial(
  25. 'blogdescription',
  26. array(
  27. 'selector' => '.site-description',
  28. 'render_callback' => 'uiu_cse_customize_partial_blogdescription',
  29. )
  30. );
  31. }
  32. }
  33. add_action( 'customize_register', 'uiu_cse_customize_register' );
  34. /**
  35. * Render the site title for the selective refresh partial.
  36. *
  37. * @return void
  38. */
  39. function uiu_cse_customize_partial_blogname() {
  40. bloginfo( 'name' );
  41. }
  42. /**
  43. * Render the site tagline for the selective refresh partial.
  44. *
  45. * @return void
  46. */
  47. function uiu_cse_customize_partial_blogdescription() {
  48. bloginfo( 'description' );
  49. }
  50. /**
  51. * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
  52. */
  53. function uiu_cse_customize_preview_js() {
  54. wp_enqueue_script( 'uiu-cse-customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), _S_VERSION, true );
  55. }
  56. add_action( 'customize_preview_init', 'uiu_cse_customize_preview_js' );