custom-header.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Sample implementation of the Custom Header feature
  4. * http://codex.wordpress.org/Custom_Headers
  5. *
  6. * You can add an optional custom header image to header.php like so ...
  7. *
  8. <?php if ( get_header_image() ) : ?>
  9. <a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
  10. <img src="<?php header_image(); ?>" width="<?php echo esc_attr( get_custom_header()->width ); ?>" height="<?php echo esc_attr( get_custom_header()->height ); ?>" alt="">
  11. </a>
  12. <?php endif; // End header image check. ?>
  13. *
  14. * @package Dyad
  15. */
  16. /**
  17. * Set up the WordPress core custom header feature.
  18. *
  19. * @uses dyad_2_header_style()
  20. * @uses dyad_2_admin_header_style()
  21. * @uses dyad_2_admin_header_image()
  22. */
  23. function dyad_2_custom_header_setup() {
  24. add_theme_support( 'custom-header', apply_filters( 'dyad_2_custom_header_args', array(
  25. 'width' => 1800,
  26. 'height' => 720,
  27. 'flex-height' => false,
  28. 'flex-width' => true,
  29. 'wp-head-callback' => 'dyad_2_header_style',
  30. ) ) );
  31. }
  32. add_action( 'after_setup_theme', 'dyad_2_custom_header_setup' );
  33. if ( ! function_exists( 'dyad_2_header_style' ) ) :
  34. /**
  35. * Styles the header image and text displayed on the blog
  36. *
  37. * @see dyad_2_custom_header_setup().
  38. */
  39. function dyad_2_header_style() {
  40. $header_text_color = get_header_textcolor();
  41. // If no custom options for text are set, let's bail
  42. // get_header_textcolor() options: HEADER_TEXTCOLOR is default, hide text (returns 'blank') or any hex value.
  43. if ( HEADER_TEXTCOLOR == $header_text_color ) {
  44. return;
  45. }
  46. // If we get this far, we have custom styles. Let's do this.
  47. ?>
  48. <style type="text/css">
  49. <?php
  50. // Has the text been hidden?
  51. if ( 'blank' == $header_text_color ) :
  52. ?>
  53. .site-title,
  54. .site-description {
  55. position: absolute;
  56. clip: rect(1px, 1px, 1px, 1px);
  57. }
  58. <?php
  59. // If the user has set a custom color for the text use that.
  60. else :
  61. ?>
  62. .site-title a,
  63. .site-description {
  64. color: #<?php echo esc_attr( $header_text_color ); ?>;
  65. }
  66. <?php endif; ?>
  67. </style>
  68. <?php
  69. }
  70. endif; // dyad_2_header_style