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. <?php if ( get_header_image() ) : ?>
  8. <a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
  9. <img src="<?php header_image(); ?>" width="<?php echo esc_attr( get_custom_header()->width ); ?>" height="<?php echo esc_attr( get_custom_header()->height ); ?>" alt="">
  10. </a>
  11. <?php endif; // End header image check. ?>
  12. *
  13. * @package Gazette
  14. */
  15. /**
  16. * Set up the WordPress core custom header feature.
  17. *
  18. * @uses gazette_header_style()
  19. * @uses gazette_admin_header_style()
  20. * @uses gazette_admin_header_image()
  21. */
  22. function gazette_custom_header_setup() {
  23. add_theme_support( 'custom-header', apply_filters( 'gazette_custom_header_args', array(
  24. 'default-image' => '',
  25. 'default-text-color' => '#3863c1',
  26. 'width' => 1260,
  27. 'height' => 300,
  28. 'flex-height' => true,
  29. 'flex-width' => true,
  30. 'wp-head-callback' => 'gazette_header_style',
  31. ) ) );
  32. }
  33. add_action( 'after_setup_theme', 'gazette_custom_header_setup' );
  34. if ( ! function_exists( 'gazette_header_style' ) ) :
  35. /**
  36. * Styles the header image and text displayed on the blog
  37. *
  38. * @see gazette_custom_header_setup().
  39. */
  40. function gazette_header_style() {
  41. $header_text_color = get_header_textcolor();
  42. // If no custom options for text are set, let's bail
  43. // get_header_textcolor() options: HEADER_TEXTCOLOR is default, hide text (returns 'blank') or any hex value
  44. if ( HEADER_TEXTCOLOR == $header_text_color ) {
  45. return;
  46. }
  47. // If we get this far, we have custom styles. Let's do this.
  48. ?>
  49. <style type="text/css">
  50. <?php
  51. // Has the text been hidden?
  52. if ( 'blank' == $header_text_color ) :
  53. ?>
  54. .site-title,
  55. .site-description {
  56. position: absolute;
  57. clip: rect(1px, 1px, 1px, 1px);
  58. }
  59. <?php
  60. // If the user has set a custom color for the text use that
  61. else :
  62. ?>
  63. .site-title,
  64. .site-description {
  65. color: #<?php echo esc_attr( $header_text_color ); ?>;
  66. }
  67. <?php endif; ?>
  68. </style>
  69. <?php
  70. }
  71. endif; // gazette_header_style