author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 17:39:30 +0200 | |
changeset 7 | cf61fcea0001 |
parent 5 | 5e2f62d02dcd |
permissions | -rw-r--r-- |
5 | 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 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
38 |
add_theme_support( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
'custom-header', apply_filters( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
40 |
'twentyfourteen_custom_header_args', array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
41 |
'default-text-color' => 'fff', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
42 |
'width' => 1260, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
43 |
'height' => 240, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
44 |
'flex-height' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
45 |
'wp-head-callback' => 'twentyfourteen_header_style', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
46 |
'admin-head-callback' => 'twentyfourteen_admin_header_style', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
47 |
'admin-preview-callback' => 'twentyfourteen_admin_header_image', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
48 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
49 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
50 |
); |
5 | 51 |
} |
52 |
add_action( 'after_setup_theme', 'twentyfourteen_custom_header_setup' ); |
|
53 |
||
54 |
if ( ! function_exists( 'twentyfourteen_header_style' ) ) : |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
55 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
* Styles the header image and text displayed on the blog |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
57 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
58 |
* @see twentyfourteen_custom_header_setup(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
59 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
60 |
function twentyfourteen_header_style() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
61 |
$text_color = get_header_textcolor(); |
5 | 62 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
63 |
// If no custom color for text is set, let's bail. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
64 |
if ( display_header_text() && $text_color === get_theme_support( 'custom-header', 'default-text-color' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
66 |
} |
5 | 67 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
68 |
// If we get this far, we have custom styles. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
69 |
?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
70 |
<style type="text/css" id="twentyfourteen-header-css"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
71 |
<?php |
5 | 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 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
91 |
} |
5 | 92 |
endif; // twentyfourteen_header_style |
93 |
||
94 |
||
95 |
if ( ! function_exists( 'twentyfourteen_admin_header_style' ) ) : |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
96 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
97 |
* Style the header image displayed on the Appearance > Header screen. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
98 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
99 |
* @see twentyfourteen_custom_header_setup() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
100 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
101 |
* @since Twenty Fourteen 1.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
102 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
103 |
function twentyfourteen_admin_header_style() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
104 |
?> |
5 | 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> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
129 |
<?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
130 |
} |
5 | 131 |
endif; // twentyfourteen_admin_header_style |
132 |
||
133 |
if ( ! function_exists( 'twentyfourteen_admin_header_image' ) ) : |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
134 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
135 |
* Create the custom header image markup displayed on the Appearance > Header screen. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
136 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
137 |
* @see twentyfourteen_custom_header_setup() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
138 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
139 |
* @since Twenty Fourteen 1.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
140 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
141 |
function twentyfourteen_admin_header_image() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
142 |
?> |
5 | 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 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
150 |
} |
5 | 151 |
endif; // twentyfourteen_admin_header_image |