custom-header.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="">
  10. </a>
  11. <?php endif; // End header image check. ?>
  12. *
  13. * @package bml
  14. */
  15. /**
  16. * Setup the WordPress core custom header feature.
  17. *
  18. * @uses bml_header_style()
  19. * @uses bml_admin_header_style()
  20. * @uses bml_admin_header_image()
  21. *
  22. * @package bml
  23. */
  24. function bml_custom_header_setup() {
  25. add_theme_support( 'custom-header', apply_filters( 'bml_custom_header_args', array(
  26. 'default-image' => '',
  27. 'default-text-color' => '000',
  28. 'width' => 1000,
  29. 'height' => 250,
  30. 'flex-height' => true,
  31. 'wp-head-callback' => 'bml_header_style',
  32. 'admin-head-callback' => 'bml_admin_header_style',
  33. 'admin-preview-callback' => 'bml_admin_header_image',
  34. ) ) );
  35. }
  36. add_action( 'after_setup_theme', 'bml_custom_header_setup' );
  37. if ( ! function_exists( 'bml_header_style' ) ) :
  38. /**
  39. * Styles the header image and text displayed on the blog
  40. *
  41. * @see bml_custom_header_setup().
  42. */
  43. function bml_header_style() {
  44. $header_text_color = get_header_textcolor();
  45. // If no custom options for text are set, let's bail
  46. // get_header_textcolor() options: HEADER_TEXTCOLOR is default, hide text (returns 'blank') or any hex value
  47. if ( HEADER_TEXTCOLOR == $header_text_color )
  48. return;
  49. // If we get this far, we have custom styles. Let's do this.
  50. ?>
  51. <style type="text/css">
  52. <?php
  53. // Has the text been hidden?
  54. if ( 'blank' == $header_text_color ) :
  55. ?>
  56. .site-title,
  57. .site-description {
  58. position: absolute;
  59. clip: rect(1px, 1px, 1px, 1px);
  60. }
  61. <?php
  62. // If the user has set a custom color for the text use that
  63. else :
  64. ?>
  65. .site-title a,
  66. .site-description {
  67. color: #<?php echo $header_text_color; ?>;
  68. }
  69. <?php endif; ?>
  70. </style>
  71. <?php
  72. }
  73. endif; // bml_header_style
  74. if ( ! function_exists( 'bml_admin_header_style' ) ) :
  75. /**
  76. * Styles the header image displayed on the Appearance > Header admin panel.
  77. *
  78. * @see bml_custom_header_setup().
  79. */
  80. function bml_admin_header_style() {
  81. ?>
  82. <style type="text/css">
  83. .appearance_page_custom-header #headimg {
  84. border: none;
  85. }
  86. #headimg h1,
  87. #desc {
  88. }
  89. #headimg h1 {
  90. }
  91. #headimg h1 a {
  92. }
  93. #desc {
  94. }
  95. #headimg img {
  96. }
  97. </style>
  98. <?php
  99. }
  100. endif; // bml_admin_header_style
  101. if ( ! function_exists( 'bml_admin_header_image' ) ) :
  102. /**
  103. * Custom header image markup displayed on the Appearance > Header admin panel.
  104. *
  105. * @see bml_custom_header_setup().
  106. */
  107. function bml_admin_header_image() {
  108. $style = sprintf( ' style="color:#%s;"', get_header_textcolor() );
  109. ?>
  110. <div id="headimg">
  111. <h1 class="displaying-header-text"><a id="name"<?php echo $style; ?> onclick="return false;" href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php bloginfo( 'name' ); ?></a></h1>
  112. <div class="displaying-header-text" id="desc"<?php echo $style; ?>><?php bloginfo( 'description' ); ?></div>
  113. <?php if ( get_header_image() ) : ?>
  114. <img src="<?php header_image(); ?>" alt="">
  115. <?php endif; ?>
  116. </div>
  117. <?php
  118. }
  119. endif; // bml_admin_header_image