wp/wp-content/themes/twentyfourteen/inc/custom-header.php
changeset 8 c7c34916027a
parent 7 cf61fcea0001
child 9 177826044cd9
equal deleted inserted replaced
7:cf61fcea0001 8:c7c34916027a
     1 <?php
       
     2 /**
       
     3  * Implement Custom Header functionality for Twenty Fourteen
       
     4  *
       
     5  * @package WordPress
       
     6  * @subpackage Twenty_Fourteen
       
     7  * @since Twenty Fourteen 1.0
       
     8  */
       
     9 
       
    10 /**
       
    11  * Set up the WordPress core custom header settings.
       
    12  *
       
    13  * @since Twenty Fourteen 1.0
       
    14  *
       
    15  * @uses twentyfourteen_header_style()
       
    16  * @uses twentyfourteen_admin_header_style()
       
    17  * @uses twentyfourteen_admin_header_image()
       
    18  */
       
    19 function twentyfourteen_custom_header_setup() {
       
    20 	/**
       
    21 	 * Filter Twenty Fourteen custom-header support arguments.
       
    22 	 *
       
    23 	 * @since Twenty Fourteen 1.0
       
    24 	 *
       
    25 	 * @param array $args {
       
    26 	 *     An array of custom-header support arguments.
       
    27 	 *
       
    28 	 *     @type bool   $header_text            Whether to display custom header text. Default false.
       
    29 	 *     @type int    $width                  Width in pixels of the custom header image. Default 1260.
       
    30 	 *     @type int    $height                 Height in pixels of the custom header image. Default 240.
       
    31 	 *     @type bool   $flex_height            Whether to allow flexible-height header images. Default true.
       
    32 	 *     @type string $admin_head_callback    Callback function used to style the image displayed in
       
    33 	 *                                          the Appearance > Header screen.
       
    34 	 *     @type string $admin_preview_callback Callback function used to create the custom header markup in
       
    35 	 *                                          the Appearance > Header screen.
       
    36 	 * }
       
    37 	 */
       
    38 	add_theme_support(
       
    39 		'custom-header', apply_filters(
       
    40 			'twentyfourteen_custom_header_args', array(
       
    41 				'default-text-color'     => 'fff',
       
    42 				'width'                  => 1260,
       
    43 				'height'                 => 240,
       
    44 				'flex-height'            => true,
       
    45 				'wp-head-callback'       => 'twentyfourteen_header_style',
       
    46 				'admin-head-callback'    => 'twentyfourteen_admin_header_style',
       
    47 				'admin-preview-callback' => 'twentyfourteen_admin_header_image',
       
    48 			)
       
    49 		)
       
    50 	);
       
    51 }
       
    52 add_action( 'after_setup_theme', 'twentyfourteen_custom_header_setup' );
       
    53 
       
    54 if ( ! function_exists( 'twentyfourteen_header_style' ) ) :
       
    55 	/**
       
    56 	 * Styles the header image and text displayed on the blog
       
    57 	 *
       
    58 	 * @see twentyfourteen_custom_header_setup().
       
    59 	 */
       
    60 	function twentyfourteen_header_style() {
       
    61 		$text_color = get_header_textcolor();
       
    62 
       
    63 		// If no custom color for text is set, let's bail.
       
    64 		if ( display_header_text() && $text_color === get_theme_support( 'custom-header', 'default-text-color' ) ) {
       
    65 			return;
       
    66 		}
       
    67 
       
    68 		// If we get this far, we have custom styles.
       
    69 		?>
       
    70 		<style type="text/css" id="twentyfourteen-header-css">
       
    71 		<?php
       
    72 		// Has the text been hidden?
       
    73 		if ( ! display_header_text() ) :
       
    74 	?>
       
    75 		.site-title,
       
    76 		.site-description {
       
    77 			clip: rect(1px 1px 1px 1px); /* IE7 */
       
    78 			clip: rect(1px, 1px, 1px, 1px);
       
    79 			position: absolute;
       
    80 		}
       
    81 	<?php
       
    82 		// If the user has set a custom color for the text, use that.
       
    83 		elseif ( $text_color != get_theme_support( 'custom-header', 'default-text-color' ) ) :
       
    84 	?>
       
    85 		.site-title a {
       
    86 			color: #<?php echo esc_attr( $text_color ); ?>;
       
    87 		}
       
    88 	<?php endif; ?>
       
    89 	</style>
       
    90 	<?php
       
    91 	}
       
    92 endif; // twentyfourteen_header_style
       
    93 
       
    94 
       
    95 if ( ! function_exists( 'twentyfourteen_admin_header_style' ) ) :
       
    96 	/**
       
    97 	 * Style the header image displayed on the Appearance > Header screen.
       
    98 	 *
       
    99 	 * @see twentyfourteen_custom_header_setup()
       
   100 	 *
       
   101 	 * @since Twenty Fourteen 1.0
       
   102 	 */
       
   103 	function twentyfourteen_admin_header_style() {
       
   104 	?>
       
   105 	<style type="text/css" id="twentyfourteen-admin-header-css">
       
   106 	.appearance_page_custom-header #headimg {
       
   107 		background-color: #000;
       
   108 		border: none;
       
   109 		max-width: 1260px;
       
   110 		min-height: 48px;
       
   111 	}
       
   112 	#headimg h1 {
       
   113 		font-family: Lato, sans-serif;
       
   114 		font-size: 18px;
       
   115 		line-height: 48px;
       
   116 		margin: 0 0 0 30px;
       
   117 	}
       
   118 	.rtl #headimg h1  {
       
   119 		margin: 0 30px 0 0;
       
   120 	}
       
   121 	#headimg h1 a {
       
   122 		color: #fff;
       
   123 		text-decoration: none;
       
   124 	}
       
   125 	#headimg img {
       
   126 		vertical-align: middle;
       
   127 	}
       
   128 	</style>
       
   129 	<?php
       
   130 	}
       
   131 endif; // twentyfourteen_admin_header_style
       
   132 
       
   133 if ( ! function_exists( 'twentyfourteen_admin_header_image' ) ) :
       
   134 	/**
       
   135 	 * Create the custom header image markup displayed on the Appearance > Header screen.
       
   136 	 *
       
   137 	 * @see twentyfourteen_custom_header_setup()
       
   138 	 *
       
   139 	 * @since Twenty Fourteen 1.0
       
   140 	 */
       
   141 	function twentyfourteen_admin_header_image() {
       
   142 	?>
       
   143 	<div id="headimg">
       
   144 		<?php if ( get_header_image() ) : ?>
       
   145 		<img src="<?php header_image(); ?>" alt="">
       
   146 		<?php endif; ?>
       
   147 		<h1 class="displaying-header-text"><a id="name" style="<?php echo esc_attr( sprintf( 'color: #%s;', get_header_textcolor() ) ); ?>" onclick="return false;" href="<?php echo esc_url( home_url( '/' ) ); ?>" tabindex="-1"><?php bloginfo( 'name' ); ?></a></h1>
       
   148 	</div>
       
   149 <?php
       
   150 	}
       
   151 endif; // twentyfourteen_admin_header_image