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