custom-header.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Custom Header functionality
  4. *
  5. * @package Apostrophe 2
  6. */
  7. /**
  8. * Set up the WordPress core custom header settings.
  9. */
  10. function apostrophe_2_custom_header_setup() {
  11. add_theme_support( 'custom-header', array(
  12. 'default-image' => '',
  13. 'default-text-color' => '362e77',
  14. 'width' => 1048,
  15. 'height' => 214,
  16. 'flex-width' => true,
  17. 'flex-height' => true,
  18. 'wp-head-callback' => 'apostrophe_2_header_style',
  19. ) );
  20. }
  21. add_action( 'after_setup_theme', 'apostrophe_2_custom_header_setup' );
  22. if ( ! function_exists( 'apostrophe_2_header_style' ) ) :
  23. /**
  24. * Styles the header image and text displayed on the blog
  25. */
  26. function apostrophe_2_header_style() {
  27. $header_image = get_header_image();
  28. $text_color = get_header_textcolor();
  29. /* Output the CSS for our custom styles */
  30. ?>
  31. <style type="text/css" id="apostrophe-2-header-css">
  32. <?php
  33. /* Do we have a custom header image? */
  34. if ( get_header_image() ) :
  35. ?>
  36. .site-branding {
  37. background: url('<?php echo esc_url( get_header_image() ); ?>') center center;
  38. background-size: cover;
  39. min-height: 200px;
  40. padding: 3em;
  41. }
  42. <?php
  43. endif;
  44. /* Has the text been hidden? */
  45. if ( ! display_header_text() ) :
  46. ?>
  47. .site-title,
  48. .site-description {
  49. clip: rect(1px, 1px, 1px, 1px);
  50. position: absolute;
  51. }
  52. .site-branding {
  53. text-align: center;
  54. }
  55. .site-logo {
  56. float: none;
  57. margin-top: 0;
  58. margin-bottom: 3.5px;
  59. }
  60. <?php
  61. /* If the user has set a custom color for the text, use that. */
  62. elseif ( get_theme_support( 'custom-header', 'default-text-color' ) !== $text_color ) :
  63. ?>
  64. .site-title a,
  65. .site-description {
  66. color: #<?php echo esc_attr( $text_color ); ?>;
  67. }
  68. <?php endif; ?>
  69. </style>
  70. <?php
  71. }
  72. endif; // apostrophe_2_header_style