[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-content/themes/twentytwelve/inc/ -> custom-header.php (source)

   1  <?php
   2  /**
   3   * Implement an optional custom header for Twenty Twelve
   4   *
   5   * See https://codex.wordpress.org/Custom_Headers
   6   *
   7   * @package WordPress
   8   * @subpackage Twenty_Twelve
   9   * @since Twenty Twelve 1.0
  10   */
  11  
  12  /**
  13   * Set up the WordPress core custom header arguments and settings.
  14   *
  15   * @uses add_theme_support() to register support for 3.4 and up.
  16   * @uses twentytwelve_header_style() to style front end.
  17   * @uses twentytwelve_admin_header_style() to style wp-admin form.
  18   * @uses twentytwelve_admin_header_image() to add custom markup to wp-admin form.
  19   *
  20   * @since Twenty Twelve 1.0
  21   */
  22  function twentytwelve_custom_header_setup() {
  23      $args = array(
  24          // Text color and image (empty to use none).
  25          'default-text-color'     => '515151',
  26          'default-image'          => '',
  27  
  28          // Set height and width, with a maximum value for the width.
  29          'height'                 => 250,
  30          'width'                  => 960,
  31          'max-width'              => 2000,
  32  
  33          // Support flexible height and width.
  34          'flex-height'            => true,
  35          'flex-width'             => true,
  36  
  37          // Random image rotation off by default.
  38          'random-default'         => false,
  39  
  40          // Callbacks for styling the header and the admin preview.
  41          'wp-head-callback'       => 'twentytwelve_header_style',
  42          'admin-head-callback'    => 'twentytwelve_admin_header_style',
  43          'admin-preview-callback' => 'twentytwelve_admin_header_image',
  44      );
  45  
  46      add_theme_support( 'custom-header', $args );
  47  }
  48  add_action( 'after_setup_theme', 'twentytwelve_custom_header_setup' );
  49  
  50  /**
  51   * Load our special font CSS file.
  52   *
  53   * @since Twenty Twelve 1.2
  54   */
  55  function twentytwelve_custom_header_fonts() {
  56      $font_url = twentytwelve_get_font_url();
  57      if ( ! empty( $font_url ) ) {
  58          wp_enqueue_style( 'twentytwelve-fonts', esc_url_raw( $font_url ), array(), null );
  59      }
  60  }
  61  add_action( 'admin_print_styles-appearance_page_custom-header', 'twentytwelve_custom_header_fonts' );
  62  
  63  /**
  64   * Style the header text displayed on the blog.
  65   *
  66   * get_header_textcolor() options: 515151 is default, hide text (returns 'blank'), or any hex value.
  67   *
  68   * @since Twenty Twelve 1.0
  69   */
  70  function twentytwelve_header_style() {
  71      $text_color = get_header_textcolor();
  72  
  73      // If no custom options for text are set, let's bail.
  74      if ( get_theme_support( 'custom-header', 'default-text-color' ) === $text_color ) {
  75          return;
  76      }
  77  
  78      // If we get this far, we have custom styles.
  79      ?>
  80      <style type="text/css" id="twentytwelve-header-css">
  81      <?php
  82          // Has the text been hidden?
  83      if ( ! display_header_text() ) :
  84          ?>
  85      .site-title,
  86      .site-description {
  87          position: absolute;
  88          clip: rect(1px 1px 1px 1px); /* IE7 */
  89          clip: rect(1px, 1px, 1px, 1px);
  90      }
  91          <?php
  92          // If the user has set a custom color for the text, use that.
  93          else :
  94              ?>
  95          .site-header h1 a,
  96          .site-header h2 {
  97              color: #<?php echo $text_color; ?>;
  98          }
  99      <?php endif; ?>
 100      </style>
 101      <?php
 102  }
 103  
 104  /**
 105   * Style the header image displayed on the Appearance > Header admin panel.
 106   *
 107   * @since Twenty Twelve 1.0
 108   */
 109  function twentytwelve_admin_header_style() {
 110      ?>
 111      <style type="text/css" id="twentytwelve-admin-header-css">
 112      .appearance_page_custom-header #headimg {
 113          border: none;
 114          font-family: "Open Sans", Helvetica, Arial, sans-serif;
 115      }
 116      #headimg h1,
 117      #headimg h2 {
 118          line-height: 1.84615;
 119          margin: 0;
 120          padding: 0;
 121      }
 122      #headimg h1 {
 123          font-size: 26px;
 124      }
 125      #headimg h1 a {
 126          color: #515151;
 127          text-decoration: none;
 128      }
 129      #headimg h1 a:hover {
 130          color: #21759b !important; /* Has to override custom inline style. */
 131      }
 132      #headimg h2 {
 133          color: #757575;
 134          font-size: 13px;
 135          margin-bottom: 24px;
 136      }
 137      #headimg img {
 138          max-width: <?php echo get_theme_support( 'custom-header', 'max-width' ); ?>px;
 139      }
 140      </style>
 141      <?php
 142  }
 143  
 144  /**
 145   * Output markup to be displayed on the Appearance > Header admin panel.
 146   *
 147   * This callback overrides the default markup displayed there.
 148   *
 149   * @since Twenty Twelve 1.0
 150   */
 151  function twentytwelve_admin_header_image() {
 152      $style = 'color: #' . get_header_textcolor() . ';';
 153      if ( ! display_header_text() ) {
 154          $style = 'display: none;';
 155      }
 156      ?>
 157      <div id="headimg">
 158          <h1 class="displaying-header-text"><a id="name" style="<?php echo esc_attr( $style ); ?>" onclick="return false;" href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php bloginfo( 'name' ); ?></a></h1>
 159          <h2 id="desc" class="displaying-header-text" style="<?php echo esc_attr( $style ); ?>"><?php bloginfo( 'description' ); ?></h2>
 160          <?php
 161          $header_image = get_header_image();
 162          if ( ! empty( $header_image ) ) :
 163              ?>
 164              <img src="<?php echo esc_url( $header_image ); ?>" class="header-image" width="<?php echo esc_attr( get_custom_header()->width ); ?>" height="<?php echo esc_attr( get_custom_header()->height ); ?>" alt="" />
 165          <?php endif; ?>
 166      </div>
 167      <?php
 168  }
 169  
 170  
 171  /**
 172   * Output markup to be displayed.
 173   *
 174   * @since Twenty Twelve 4.1
 175   */
 176  function twentytwelve_header_image() {
 177      $custom_header = get_custom_header();
 178      $attrs         = array(
 179          'alt'    => get_bloginfo( 'name', 'display' ),
 180          'class'  => 'header-image',
 181          'height' => $custom_header->height,
 182          'width'  => $custom_header->width,
 183      );
 184  
 185      if ( function_exists( 'the_header_image_tag' ) ) {
 186          the_header_image_tag( $attrs );
 187          return;
 188      }
 189      ?>
 190      <img src="<?php header_image(); ?>" class="<?php echo esc_attr( $attrs['class'] ); ?>" width="<?php echo esc_attr( $attrs['width'] ); ?>" height="<?php echo esc_attr( $attrs['height'] ); ?>" alt="<?php echo esc_attr( $attrs['alt'] ); ?>" />
 191      <?php
 192  }


Generated : Mon Mar 18 08:20:01 2024 Cross-referenced by PHPXref