custom-header.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Sample implementation of the Custom Header feature.
  4. *
  5. * You can add an optional custom header image to header.php like so ...
  6. *
  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. * @link https://developer.wordpress.org/themes/functionality/custom-headers/
  14. *
  15. * @package Toujours
  16. */
  17. /**
  18. * Set up the WordPress core custom header feature.
  19. *
  20. * @uses toujours_header_style()
  21. */
  22. function toujours_custom_header_setup() {
  23. add_theme_support( 'custom-header', apply_filters( 'toujours_custom_header_args', array(
  24. 'default-image' => '',
  25. 'default-text-color' => '#2590ec',
  26. 'width' => 1160,
  27. 'height' => 250,
  28. 'flex-height' => true,
  29. 'wp-head-callback' => 'toujours_header_style',
  30. ) ) );
  31. }
  32. add_action( 'after_setup_theme', 'toujours_custom_header_setup' );
  33. if ( ! function_exists( 'toujours_header_style' ) ) :
  34. /**
  35. * Styles the header image and text displayed on the blog.
  36. *
  37. * @see toujours_custom_header_setup().
  38. */
  39. function toujours_header_style() {
  40. $header_text_color = get_header_textcolor();
  41. /*
  42. * If no custom options for text are set, let's bail.
  43. * get_header_textcolor() options: Any hex value, 'blank' to hide text. Default: HEADER_TEXTCOLOR.
  44. */
  45. if ( HEADER_TEXTCOLOR === $header_text_color ) {
  46. return;
  47. }
  48. // If we get this far, we have custom styles. Let's do this.
  49. ?>
  50. <style type="text/css">
  51. <?php
  52. // Has the text been hidden?
  53. if ( ! display_header_text() ) :
  54. ?>
  55. .site-title,
  56. #tagline {
  57. position: absolute;
  58. clip: rect(1px, 1px, 1px, 1px);
  59. }
  60. <?php
  61. // If the user has set a custom color for the text use that.
  62. else :
  63. ?>
  64. .site-title a {
  65. color: #<?php echo esc_attr( $header_text_color ); ?>;
  66. }
  67. <?php endif; ?>
  68. </style>
  69. <?php
  70. }
  71. endif;