Advertisement
alchymyth

custom header functions code

May 9th, 2013
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.92 KB | None | 0 0
  1. /**
  2.  * Implements an optional custom header for A THEME.
  3.  * See http://codex.wordpress.org/Custom_Headers
  4.  *
  5.  * Sets up the WordPress core custom header arguments and settings.
  6.  *
  7.  * @uses add_theme_support() to register support for 3.4 and up.
  8.  * @uses a_theme_admin_header_style() to style wp-admin form.
  9.  * @uses a_theme_admin_header_image() to add custom markup to wp-admin form.
  10.  *
  11.  */
  12. function a_theme_custom_header_setup() {
  13.     $args = array(
  14.         // image (empty to use none).
  15.         'default-image'          => '',
  16.  
  17.         // Set height and width, with a maximum value for the width.
  18.         'height'                 => 192,
  19.         'width'                  => 740,
  20.         'max-width'              => 740,
  21.  
  22.         // Support flexible height and width.
  23.         'flex-height'            => true,
  24.         'flex-width'             => true,
  25.  
  26.         'default-text-color'     => '',
  27.         'header-text'            => false,
  28.  
  29.         // Random image rotation off by default.
  30.         'random-default'         => false,
  31.  
  32.         // Callbacks for styling the header and the admin preview.
  33.         'admin-head-callback'    => 'a_theme_admin_header_style',
  34.         'admin-preview-callback' => 'a_theme_admin_header_image',
  35.     );
  36.  
  37.     add_theme_support( 'custom-header', $args );
  38. }
  39. add_action( 'after_setup_theme', 'a_theme_custom_header_setup' );
  40.  
  41. /**
  42.  * Styles the header image displayed on the Appearance > Header admin panel.
  43.  *
  44.  * @since A THEME 1.0
  45.  */
  46. function a_theme_admin_header_style() {
  47. ?>
  48.     <style type="text/css">
  49.     .appearance_page_custom-header #headimg {
  50.         border: none;
  51.     }
  52.     #headimg h1,
  53.     #headimg h2 {
  54.         line-height: 1.6;
  55.         margin: 0;
  56.         padding: 0;
  57.     }
  58.     #headimg h1 {
  59.         font-size: 30px;
  60.     }
  61.     #headimg h1 a {
  62.         color: #515151;
  63.         text-decoration: none;
  64.     }
  65.     #headimg h1 a:hover {
  66.         color: #21759b;
  67.     }
  68.     #headimg h2 {
  69.         color: #757575;
  70.         font: normal 13px/1.8 "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", sans-serif;
  71.         margin-bottom: 24px;
  72.     }
  73.     #headimg img {
  74.         max-width: <?php echo get_theme_support( 'custom-header', 'max-width' ); ?>px;
  75.     }
  76.     </style>
  77. <?php
  78. }
  79.  
  80. /**
  81.  * Outputs markup to be displayed on the Appearance > Header admin panel.
  82.  * This callback overrides the default markup displayed there.
  83. */
  84. function a_theme_admin_header_image() {
  85.     ?>
  86.     <div id="headimg">
  87.         <?php
  88.         if ( ! display_header_text() )
  89.             $style = ' style="display:none;"';
  90.         else
  91.             $style = ' style="color:#' . get_header_textcolor() . ';"';
  92.         ?>
  93.         <h1><a id="name"<?php echo $style; ?> onclick="return false;" href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php bloginfo( 'name' ); ?></a></h1>
  94.         <h2 id="desc"<?php echo $style; ?>><?php bloginfo( 'description' ); ?></h2>
  95.         <?php $header_image = get_header_image();
  96.         if ( ! empty( $header_image ) ) : ?>
  97.             <img src="<?php echo esc_url( $header_image ); ?>" class="header-image" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="" />
  98.         <?php endif; ?>
  99.     </div>
  100. <?php }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement