Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 

121 righe
4.2 KiB

  1. <?php
  2. /**
  3. * Custom header implementation
  4. *
  5. * @link https://codex.wordpress.org/Custom_Headers
  6. *
  7. * @package WordPress
  8. * @subpackage Twenty_Seventeen
  9. * @since 1.0
  10. */
  11. /**
  12. * Set up the WordPress core custom header feature.
  13. *
  14. * @uses twentyseventeen_header_style()
  15. */
  16. function twentyseventeen_custom_header_setup() {
  17. /**
  18. * Filter Twenty Seventeen custom-header support arguments.
  19. *
  20. * @since Twenty Seventeen 1.0
  21. *
  22. * @param array $args {
  23. * An array of custom-header support arguments.
  24. *
  25. * @type string $default-image Default image of the header.
  26. * @type string $default_text_color Default color of the header text.
  27. * @type int $width Width in pixels of the custom header image. Default 954.
  28. * @type int $height Height in pixels of the custom header image. Default 1300.
  29. * @type string $wp-head-callback Callback function used to styles the header image and text
  30. * displayed on the blog.
  31. * @type string $flex-height Flex support for height of header.
  32. * }
  33. */
  34. add_theme_support( 'custom-header', apply_filters( 'twentyseventeen_custom_header_args', array(
  35. 'default-image' => get_parent_theme_file_uri( '/assets/images/header.jpg' ),
  36. 'width' => 2000,
  37. 'height' => 1200,
  38. 'flex-height' => true,
  39. 'video' => true,
  40. 'wp-head-callback' => 'twentyseventeen_header_style',
  41. ) ) );
  42. register_default_headers( array(
  43. 'default-image' => array(
  44. 'url' => '%s/assets/images/header.jpg',
  45. 'thumbnail_url' => '%s/assets/images/header.jpg',
  46. 'description' => __( 'Default Header Image', 'twentyseventeen' ),
  47. ),
  48. ) );
  49. }
  50. add_action( 'after_setup_theme', 'twentyseventeen_custom_header_setup' );
  51. if ( ! function_exists( 'twentyseventeen_header_style' ) ) :
  52. /**
  53. * Styles the header image and text displayed on the blog.
  54. *
  55. * @see twentyseventeen_custom_header_setup().
  56. */
  57. function twentyseventeen_header_style() {
  58. $header_text_color = get_header_textcolor();
  59. // If no custom options for text are set, let's bail.
  60. // get_header_textcolor() options: add_theme_support( 'custom-header' ) is default, hide text (returns 'blank') or any hex value.
  61. if ( get_theme_support( 'custom-header', 'default-text-color' ) === $header_text_color ) {
  62. return;
  63. }
  64. // If we get this far, we have custom styles. Let's do this.
  65. ?>
  66. <style id="twentyseventeen-custom-header-styles" type="text/css">
  67. <?php
  68. // Has the text been hidden?
  69. if ( 'blank' === $header_text_color ) :
  70. ?>
  71. .site-title,
  72. .site-description {
  73. position: absolute;
  74. clip: rect(1px, 1px, 1px, 1px);
  75. }
  76. <?php
  77. // If the user has set a custom color for the text use that.
  78. else :
  79. ?>
  80. .site-title a,
  81. .colors-dark .site-title a,
  82. .colors-custom .site-title a,
  83. body.has-header-image .site-title a,
  84. body.has-header-video .site-title a,
  85. body.has-header-image.colors-dark .site-title a,
  86. body.has-header-video.colors-dark .site-title a,
  87. body.has-header-image.colors-custom .site-title a,
  88. body.has-header-video.colors-custom .site-title a,
  89. .site-description,
  90. .colors-dark .site-description,
  91. .colors-custom .site-description,
  92. body.has-header-image .site-description,
  93. body.has-header-video .site-description,
  94. body.has-header-image.colors-dark .site-description,
  95. body.has-header-video.colors-dark .site-description,
  96. body.has-header-image.colors-custom .site-description,
  97. body.has-header-video.colors-custom .site-description {
  98. color: #<?php echo esc_attr( $header_text_color ); ?>;
  99. }
  100. <?php endif; ?>
  101. </style>
  102. <?php
  103. }
  104. endif; // End of twentyseventeen_header_style.
  105. /**
  106. * Customize video play/pause button in the custom header.
  107. */
  108. function twentyseventeen_video_controls( $settings ) {
  109. $settings['l10n']['play'] = '<span class="screen-reader-text">' . __( 'Play background video', 'twentyseventeen' ) . '</span>' . twentyseventeen_get_svg( array( 'icon' => 'play' ) );
  110. $settings['l10n']['pause'] = '<span class="screen-reader-text">' . __( 'Pause background video', 'twentyseventeen' ) . '</span>' . twentyseventeen_get_svg( array( 'icon' => 'pause' ) );
  111. return $settings;
  112. }
  113. add_filter( 'header_video_settings', 'twentyseventeen_video_controls' );