custom-header.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 Karuna
  9. */
  10. /**
  11. * Set up the WordPress core custom header feature.
  12. *
  13. * @uses karuna_header_style()
  14. */
  15. function karuna_custom_header_setup() {
  16. add_theme_support( 'custom-header', apply_filters( 'karuna_custom_header_args', array(
  17. 'default-image' => get_template_directory_uri() . '/assets/images/header.jpg',
  18. 'default-text-color' => '333333',
  19. 'width' => 2000,
  20. 'height' => 800,
  21. 'flex-height' => true,
  22. 'wp-head-callback' => 'karuna_header_style',
  23. ) ) );
  24. register_default_headers( array(
  25. 'yoga' => array(
  26. 'thumbnail_url' => get_template_directory_uri() . '/assets/images/header-thumb.jpg',
  27. 'url' => get_template_directory_uri() . '/assets/images/header.jpg',
  28. 'description' => esc_html__( 'Yoga', 'karuna' ),
  29. ),
  30. 'rocks' => array(
  31. 'thumbnail_url' => get_template_directory_uri() . '/assets/images/header2-thumb.jpg',
  32. 'url' => get_template_directory_uri() . '/assets/images/header2.jpg',
  33. 'description' => esc_html__( 'Rocks', 'karuna' ),
  34. ),
  35. 'zen' => array(
  36. 'thumbnail_url' => get_template_directory_uri() . '/assets/images/header3-thumb.jpg',
  37. 'url' => get_template_directory_uri() . '/assets/images/header3.jpg',
  38. 'description' => esc_html__( 'Zen', 'karuna' ),
  39. ),
  40. ) );
  41. }
  42. add_action( 'after_setup_theme', 'karuna_custom_header_setup' );
  43. if ( ! function_exists( 'karuna_header_style' ) ) :
  44. /**
  45. * Styles the header image and text displayed on the blog
  46. *
  47. * @see karuna_custom_header_setup().
  48. */
  49. function karuna_header_style() {
  50. $header_text_color = get_header_textcolor();
  51. // If no custom options for text are set, let's bail.
  52. // get_header_textcolor() options: add_theme_support( 'custom-header' ) is default, hide text (returns 'blank') or any hex value.
  53. if ( get_theme_support( 'custom-header', 'default-text-color' ) === $header_text_color ) {
  54. return;
  55. }
  56. // If we get this far, we have custom styles. Let's do this.
  57. ?>
  58. <style type="text/css">
  59. <?php
  60. // Has the text been hidden?
  61. if ( 'blank' == $header_text_color ) :
  62. ?>
  63. .site-title,
  64. .site-description {
  65. position: absolute;
  66. clip: rect(1px, 1px, 1px, 1px);
  67. }
  68. <?php
  69. // If the user has set a custom color for the text use that.
  70. else :
  71. ?>
  72. .site-title a {
  73. color: #<?php echo esc_attr( $header_text_color ); ?>;
  74. }
  75. <?php endif; ?>
  76. </style>
  77. <?php
  78. }
  79. endif; // karuna_header_style