[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
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-path: inset(50%); 89 } 90 <?php 91 // If the user has set a custom color for the text, use that. 92 else : 93 ?> 94 .site-header h1 a, 95 .site-header h2 { 96 color: #<?php echo $text_color; ?>; 97 } 98 <?php endif; ?> 99 </style> 100 <?php 101 } 102 103 /** 104 * Style the header image displayed on the Appearance > Header admin panel. 105 * 106 * @since Twenty Twelve 1.0 107 */ 108 function twentytwelve_admin_header_style() { 109 ?> 110 <style type="text/css" id="twentytwelve-admin-header-css"> 111 .appearance_page_custom-header #headimg { 112 border: none; 113 font-family: "Open Sans", Helvetica, Arial, sans-serif; 114 } 115 #headimg h1, 116 #headimg h2 { 117 line-height: 1.84615; 118 margin: 0; 119 padding: 0; 120 } 121 #headimg h1 { 122 font-size: 26px; 123 } 124 #headimg h1 a { 125 color: #515151; 126 text-decoration: none; 127 } 128 #headimg h1 a:hover { 129 color: #21759b !important; /* Has to override custom inline style. */ 130 } 131 #headimg h2 { 132 color: #757575; 133 font-size: 13px; 134 margin-bottom: 24px; 135 } 136 #headimg img { 137 max-width: <?php echo get_theme_support( 'custom-header', 'max-width' ); ?>px; 138 } 139 </style> 140 <?php 141 } 142 143 /** 144 * Output markup to be displayed on the Appearance > Header admin panel. 145 * 146 * This callback overrides the default markup displayed there. 147 * 148 * @since Twenty Twelve 1.0 149 */ 150 function twentytwelve_admin_header_image() { 151 $style = 'color: #' . get_header_textcolor() . ';'; 152 if ( ! display_header_text() ) { 153 $style = 'display: none;'; 154 } 155 ?> 156 <div id="headimg"> 157 <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> 158 <h2 id="desc" class="displaying-header-text" style="<?php echo esc_attr( $style ); ?>"><?php bloginfo( 'description' ); ?></h2> 159 <?php 160 $header_image = get_header_image(); 161 if ( ! empty( $header_image ) ) : 162 ?> 163 <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="" /> 164 <?php endif; ?> 165 </div> 166 <?php 167 } 168 169 170 /** 171 * Output markup to be displayed. 172 * 173 * @since Twenty Twelve 4.1 174 */ 175 function twentytwelve_header_image() { 176 $custom_header = get_custom_header(); 177 $attrs = array( 178 'alt' => get_bloginfo( 'name', 'display' ), 179 'class' => 'header-image', 180 'height' => $custom_header->height, 181 'width' => $custom_header->width, 182 ); 183 184 if ( function_exists( 'the_header_image_tag' ) ) { 185 the_header_image_tag( $attrs ); 186 return; 187 } 188 ?> 189 <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'] ); ?>" /> 190 <?php 191 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Sat Feb 22 08:20:01 2025 | Cross-referenced by PHPXref |