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