custom-header.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. * @package Button 2
  9. */
  10. /**
  11. * Set up the WordPress core custom header feature.
  12. *
  13. * @uses button_2_header_style()
  14. * @uses button_2_admin_header_style()
  15. * @uses button_2_admin_header_image()
  16. */
  17. function button_2_custom_header_setup() {
  18. add_theme_support( 'custom-header', apply_filters( 'button_2_custom_header_args', array(
  19. 'default-image' => '',
  20. 'default-text-color' => 'f78769',
  21. 'width' => 982,
  22. 'height' => 250,
  23. 'flex-height' => true,
  24. 'wp-head-callback' => 'button_2_header_style',
  25. ) ) );
  26. }
  27. add_action( 'after_setup_theme', 'button_2_custom_header_setup' );
  28. if ( ! function_exists( 'button_2_header_style' ) ) :
  29. /**
  30. * Styles the header image and text displayed on the blog.
  31. *
  32. * @see button_2_custom_header_setup().
  33. */
  34. function button_2_header_style() {
  35. $header_text_color = get_header_textcolor();
  36. /*
  37. * If no custom options for text are set, let's bail.
  38. * get_header_textcolor() options: Any hex value, 'blank' to hide text. Default: add_theme_support( 'custom-header' ).
  39. */
  40. if ( get_theme_support( 'custom-header', 'default-text-color' ) === $header_text_color ) {
  41. return;
  42. }
  43. // If we get this far, we have custom styles. Let's do this.
  44. ?>
  45. <style type="text/css">
  46. <?php
  47. // Has the text been hidden?
  48. if ( ! display_header_text() ) :
  49. ?>
  50. .site-title,
  51. .site-description {
  52. position: absolute;
  53. clip: rect(1px, 1px, 1px, 1px);
  54. }
  55. <?php
  56. // If the user has set a custom color for the text use that.
  57. else :
  58. ?>
  59. .site-title a,
  60. .site-title a:visited {
  61. color: #<?php echo esc_attr( $header_text_color ); ?>;
  62. }
  63. <?php endif; ?>
  64. </style>
  65. <?php
  66. }
  67. endif;