custom-header.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * Implementation of the Custom Header feature
  4. * http://codex.wordpress.org/Custom_Headers
  5. *
  6. *
  7. * @package Pique
  8. */
  9. /**
  10. * Set up the WordPress core custom header feature.
  11. *
  12. * @uses pique_header_style()
  13. * @uses pique_admin_header_style()
  14. * @uses pique_admin_header_image()
  15. */
  16. function pique_custom_header_setup() {
  17. add_theme_support( 'custom-header', apply_filters( 'pique_custom_header_args', array(
  18. 'default-image' => esc_url( get_template_directory_uri() ) . '/assets/images/default-header.jpg',
  19. 'default-text-color' => '#FCFBF9',
  20. 'width' => 1400,
  21. 'height' => 400,
  22. 'flex-height' => true,
  23. 'wp-head-callback' => 'pique_header_style',
  24. 'admin-head-callback' => 'pique_admin_header_style',
  25. 'admin-preview-callback' => 'pique_admin_header_image',
  26. ) ) );
  27. }
  28. add_action( 'after_setup_theme', 'pique_custom_header_setup' );
  29. if ( ! function_exists( 'pique_header_style' ) ) :
  30. /**
  31. * Styles the header image and text displayed on the blog
  32. *
  33. * @see pique_custom_header_setup().
  34. */
  35. function pique_header_style() {
  36. $header_text_color = get_header_textcolor();
  37. // If no custom options for text are set, let's bail
  38. // get_header_textcolor() options: HEADER_TEXTCOLOR is default, hide text (returns 'blank') or any hex value.
  39. if ( HEADER_TEXTCOLOR === $header_text_color ) {
  40. return;
  41. }
  42. // If we get this far, we have custom styles. Let's do this.
  43. ?>
  44. <style type="text/css">
  45. <?php
  46. // Has the text been hidden?
  47. if ( 'blank' === $header_text_color ) :
  48. ?>
  49. #masthead .site-branding .site-title a,
  50. #masthead .site-branding .site-description {
  51. position: absolute;
  52. clip: rect(1px, 1px, 1px, 1px);
  53. }
  54. <?php
  55. // If the user has set a custom color for the text use that.
  56. else :
  57. ?>
  58. #masthead .site-branding .site-title a,
  59. #masthead .site-branding .site-description {
  60. color: #<?php echo esc_attr( $header_text_color ); ?>;
  61. }
  62. <?php endif; ?>
  63. </style>
  64. <?php
  65. }
  66. endif; // pique_header_style
  67. if ( ! function_exists( 'pique_admin_header_image' ) ) :
  68. /**
  69. * Custom header image markup displayed on the Appearance > Header admin panel.
  70. *
  71. * @see pique_custom_header_setup().
  72. */
  73. function pique_admin_header_image() {
  74. ?>
  75. <div id="headimg">
  76. <h1 class="displaying-header-text">
  77. <a id="name" style="<?php echo esc_attr( 'color: #' . get_header_textcolor() ); ?>" onclick="return false;" href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php bloginfo( 'name' ); ?></a>
  78. </h1>
  79. <div class="displaying-header-text" id="desc" style="<?php echo esc_attr( 'color: #' . get_header_textcolor() ); ?>"><?php bloginfo( 'description' ); ?></div>
  80. <?php if ( get_header_image() ) : ?>
  81. <img src="<?php header_image(); ?>" alt="">
  82. <?php endif; ?>
  83. </div>
  84. <?php
  85. }
  86. endif; // pique_admin_header_image