author | ymh <ymh.work@gmail.com> |
Tue, 27 Sep 2022 16:37:53 +0200 | |
changeset 19 | 3d72ae0968f4 |
parent 18 | be944660c56a |
child 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* WordPress Post Thumbnail Template Functions. |
|
4 |
* |
|
5 | 5 |
* Support for post thumbnails. |
6 |
* Theme's functions.php must call add_theme_support( 'post-thumbnails' ) to use these. |
|
0 | 7 |
* |
8 |
* @package WordPress |
|
9 |
* @subpackage Template |
|
10 |
*/ |
|
11 |
||
12 |
/** |
|
9 | 13 |
* Determines whether a post has an image attached. |
14 |
* |
|
15 |
* For more information on this and similar theme functions, check out |
|
16 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
17 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
0 | 18 |
* |
19 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
20 |
* @since 4.4.0 `$post` can be a post ID or WP_Post object. |
0 | 21 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
22 |
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
23 |
* @return bool Whether the post has an image attached. |
0 | 24 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
25 |
function has_post_thumbnail( $post = null ) { |
9 | 26 |
$thumbnail_id = get_post_thumbnail_id( $post ); |
27 |
$has_thumbnail = (bool) $thumbnail_id; |
|
28 |
||
29 |
/** |
|
30 |
* Filters whether a post has a post thumbnail. |
|
31 |
* |
|
32 |
* @since 5.1.0 |
|
33 |
* |
|
34 |
* @param bool $has_thumbnail true if the post has a post thumbnail, otherwise false. |
|
35 |
* @param int|WP_Post|null $post Post ID or WP_Post object. Default is global `$post`. |
|
18 | 36 |
* @param int|false $thumbnail_id Post thumbnail ID or false if the post does not exist. |
9 | 37 |
*/ |
38 |
return (bool) apply_filters( 'has_post_thumbnail', $has_thumbnail, $post, $thumbnail_id ); |
|
0 | 39 |
} |
40 |
||
41 |
/** |
|
19 | 42 |
* Retrieves the post thumbnail ID. |
0 | 43 |
* |
44 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
45 |
* @since 4.4.0 `$post` can be a post ID or WP_Post object. |
16 | 46 |
* @since 5.5.0 The return value for a non-existing post |
47 |
* was changed to false instead of an empty string. |
|
0 | 48 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
49 |
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`. |
16 | 50 |
* @return int|false Post thumbnail ID (which can be 0 if the thumbnail is not set), |
51 |
* or false if the post does not exist. |
|
0 | 52 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
53 |
function get_post_thumbnail_id( $post = null ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
54 |
$post = get_post( $post ); |
16 | 55 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
if ( ! $post ) { |
16 | 57 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
58 |
} |
16 | 59 |
|
19 | 60 |
$thumbnail_id = (int) get_post_meta( $post->ID, '_thumbnail_id', true ); |
61 |
||
62 |
/** |
|
63 |
* Filters the post thumbnail ID. |
|
64 |
* |
|
65 |
* @since 5.9.0 |
|
66 |
* |
|
67 |
* @param int|false $thumbnail_id Post thumbnail ID or false if the post does not exist. |
|
68 |
* @param int|WP_Post|null $post Post ID or WP_Post object. Default is global `$post`. |
|
69 |
*/ |
|
70 |
return (int) apply_filters( 'post_thumbnail_id', $thumbnail_id, $post ); |
|
0 | 71 |
} |
72 |
||
73 |
/** |
|
19 | 74 |
* Displays the post thumbnail. |
5 | 75 |
* |
76 |
* When a theme adds 'post-thumbnail' support, a special 'post-thumbnail' image size |
|
77 |
* is registered, which differs from the 'thumbnail' image size managed via the |
|
78 |
* Settings > Media screen. |
|
79 |
* |
|
80 |
* When using the_post_thumbnail() or related functions, the 'post-thumbnail' image |
|
81 |
* size is used by default, though a different size can be specified instead as needed. |
|
0 | 82 |
* |
83 |
* @since 2.9.0 |
|
84 |
* |
|
5 | 85 |
* @see get_the_post_thumbnail() |
86 |
* |
|
18 | 87 |
* @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array of |
88 |
* width and height values in pixels (in that order). Default 'post-thumbnail'. |
|
5 | 89 |
* @param string|array $attr Optional. Query string or array of attributes. Default empty. |
0 | 90 |
*/ |
91 |
function the_post_thumbnail( $size = 'post-thumbnail', $attr = '' ) { |
|
92 |
echo get_the_post_thumbnail( null, $size, $attr ); |
|
93 |
} |
|
94 |
||
95 |
/** |
|
19 | 96 |
* Updates cache for thumbnails in the current loop. |
0 | 97 |
* |
5 | 98 |
* @since 3.2.0 |
0 | 99 |
* |
16 | 100 |
* @global WP_Query $wp_query WordPress Query object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
101 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
102 |
* @param WP_Query $wp_query Optional. A WP_Query instance. Defaults to the $wp_query global. |
0 | 103 |
*/ |
104 |
function update_post_thumbnail_cache( $wp_query = null ) { |
|
9 | 105 |
if ( ! $wp_query ) { |
0 | 106 |
$wp_query = $GLOBALS['wp_query']; |
9 | 107 |
} |
0 | 108 |
|
9 | 109 |
if ( $wp_query->thumbnails_cached ) { |
0 | 110 |
return; |
9 | 111 |
} |
0 | 112 |
|
113 |
$thumb_ids = array(); |
|
16 | 114 |
|
0 | 115 |
foreach ( $wp_query->posts as $post ) { |
16 | 116 |
$id = get_post_thumbnail_id( $post->ID ); |
117 |
if ( $id ) { |
|
0 | 118 |
$thumb_ids[] = $id; |
9 | 119 |
} |
0 | 120 |
} |
121 |
||
9 | 122 |
if ( ! empty( $thumb_ids ) ) { |
0 | 123 |
_prime_post_caches( $thumb_ids, false, true ); |
124 |
} |
|
125 |
||
126 |
$wp_query->thumbnails_cached = true; |
|
127 |
} |
|
128 |
||
129 |
/** |
|
19 | 130 |
* Retrieves the post thumbnail. |
5 | 131 |
* |
132 |
* When a theme adds 'post-thumbnail' support, a special 'post-thumbnail' image size |
|
133 |
* is registered, which differs from the 'thumbnail' image size managed via the |
|
134 |
* Settings > Media screen. |
|
135 |
* |
|
136 |
* When using the_post_thumbnail() or related functions, the 'post-thumbnail' image |
|
137 |
* size is used by default, though a different size can be specified instead as needed. |
|
0 | 138 |
* |
139 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
140 |
* @since 4.4.0 `$post` can be a post ID or WP_Post object. |
0 | 141 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
142 |
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`. |
18 | 143 |
* @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array of |
144 |
* width and height values in pixels (in that order). Default 'post-thumbnail'. |
|
5 | 145 |
* @param string|array $attr Optional. Query string or array of attributes. Default empty. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
146 |
* @return string The post thumbnail image tag. |
0 | 147 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
148 |
function get_the_post_thumbnail( $post = null, $size = 'post-thumbnail', $attr = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
149 |
$post = get_post( $post ); |
16 | 150 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
151 |
if ( ! $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
152 |
return ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
153 |
} |
16 | 154 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
155 |
$post_thumbnail_id = get_post_thumbnail_id( $post ); |
0 | 156 |
|
157 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
158 |
* Filters the post thumbnail size. |
0 | 159 |
* |
160 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
161 |
* @since 4.9.0 Added the `$post_id` parameter. |
0 | 162 |
* |
18 | 163 |
* @param string|int[] $size Requested image size. Can be any registered image size name, or |
164 |
* an array of width and height values in pixels (in that order). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
165 |
* @param int $post_id The post ID. |
0 | 166 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
167 |
$size = apply_filters( 'post_thumbnail_size', $size, $post->ID ); |
0 | 168 |
|
169 |
if ( $post_thumbnail_id ) { |
|
170 |
||
171 |
/** |
|
172 |
* Fires before fetching the post thumbnail HTML. |
|
173 |
* |
|
174 |
* Provides "just in time" filtering of all filters in wp_get_attachment_image(). |
|
175 |
* |
|
176 |
* @since 2.9.0 |
|
177 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
178 |
* @param int $post_id The post ID. |
18 | 179 |
* @param int $post_thumbnail_id The post thumbnail ID. |
180 |
* @param string|int[] $size Requested image size. Can be any registered image size name, or |
|
181 |
* an array of width and height values in pixels (in that order). |
|
0 | 182 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
183 |
do_action( 'begin_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size ); |
16 | 184 |
|
9 | 185 |
if ( in_the_loop() ) { |
0 | 186 |
update_post_thumbnail_cache(); |
9 | 187 |
} |
16 | 188 |
|
19 | 189 |
// Get the 'loading' attribute value to use as default, taking precedence over the default from |
190 |
// `wp_get_attachment_image()`. |
|
191 |
$loading = wp_get_loading_attr_default( 'the_post_thumbnail' ); |
|
192 |
||
193 |
// Add the default to the given attributes unless they already include a 'loading' directive. |
|
194 |
if ( empty( $attr ) ) { |
|
195 |
$attr = array( 'loading' => $loading ); |
|
196 |
} elseif ( is_array( $attr ) && ! array_key_exists( 'loading', $attr ) ) { |
|
197 |
$attr['loading'] = $loading; |
|
198 |
} elseif ( is_string( $attr ) && ! preg_match( '/(^|&)loading=/', $attr ) ) { |
|
199 |
$attr .= '&loading=' . $loading; |
|
200 |
} |
|
201 |
||
0 | 202 |
$html = wp_get_attachment_image( $post_thumbnail_id, $size, false, $attr ); |
203 |
||
204 |
/** |
|
205 |
* Fires after fetching the post thumbnail HTML. |
|
206 |
* |
|
207 |
* @since 2.9.0 |
|
208 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
209 |
* @param int $post_id The post ID. |
18 | 210 |
* @param int $post_thumbnail_id The post thumbnail ID. |
211 |
* @param string|int[] $size Requested image size. Can be any registered image size name, or |
|
212 |
* an array of width and height values in pixels (in that order). |
|
0 | 213 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
214 |
do_action( 'end_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size ); |
0 | 215 |
|
216 |
} else { |
|
217 |
$html = ''; |
|
218 |
} |
|
16 | 219 |
|
0 | 220 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
221 |
* Filters the post thumbnail HTML. |
0 | 222 |
* |
223 |
* @since 2.9.0 |
|
224 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
225 |
* @param string $html The post thumbnail HTML. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
226 |
* @param int $post_id The post ID. |
19 | 227 |
* @param int $post_thumbnail_id The post thumbnail ID, or 0 if there isn't one. |
18 | 228 |
* @param string|int[] $size Requested image size. Can be any registered image size name, or |
229 |
* an array of width and height values in pixels (in that order). |
|
19 | 230 |
* @param string|array $attr Query string or array of attributes. |
0 | 231 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
232 |
return apply_filters( 'post_thumbnail_html', $html, $post->ID, $post_thumbnail_id, $size, $attr ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
233 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
234 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
235 |
/** |
19 | 236 |
* Returns the post thumbnail URL. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
237 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
238 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
239 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
240 |
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`. |
18 | 241 |
* @param string|int[] $size Optional. Registered image size to retrieve the source for or a flat array |
242 |
* of height and width dimensions. Default 'post-thumbnail'. |
|
243 |
* @return string|false Post thumbnail URL or false if no image is available. If `$size` does not match |
|
244 |
* any registered image size, the original image URL will be returned. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
245 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
246 |
function get_the_post_thumbnail_url( $post = null, $size = 'post-thumbnail' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
247 |
$post_thumbnail_id = get_post_thumbnail_id( $post ); |
16 | 248 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
249 |
if ( ! $post_thumbnail_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
250 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
251 |
} |
16 | 252 |
|
19 | 253 |
$thumbnail_url = wp_get_attachment_image_url( $post_thumbnail_id, $size ); |
254 |
||
255 |
/** |
|
256 |
* Filters the post thumbnail URL. |
|
257 |
* |
|
258 |
* @since 5.9.0 |
|
259 |
* |
|
260 |
* @param string|false $thumbnail_url Post thumbnail URL or false if the post does not exist. |
|
261 |
* @param int|WP_Post|null $post Post ID or WP_Post object. Default is global `$post`. |
|
262 |
* @param string|int[] $size Registered image size to retrieve the source for or a flat array |
|
263 |
* of height and width dimensions. Default 'post-thumbnail'. |
|
264 |
*/ |
|
265 |
return apply_filters( 'post_thumbnail_url', $thumbnail_url, $post, $size ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
266 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
267 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
268 |
/** |
19 | 269 |
* Displays the post thumbnail URL. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
270 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
271 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
272 |
* |
18 | 273 |
* @param string|int[] $size Optional. Image size to use. Accepts any valid image size, |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
274 |
* or an array of width and height values in pixels (in that order). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
275 |
* Default 'post-thumbnail'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
276 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
277 |
function the_post_thumbnail_url( $size = 'post-thumbnail' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
278 |
$url = get_the_post_thumbnail_url( null, $size ); |
16 | 279 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
280 |
if ( $url ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
281 |
echo esc_url( $url ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
282 |
} |
0 | 283 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
284 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
285 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
286 |
* Returns the post thumbnail caption. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
287 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
288 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
289 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
290 |
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
291 |
* @return string Post thumbnail caption. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
292 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
293 |
function get_the_post_thumbnail_caption( $post = null ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
294 |
$post_thumbnail_id = get_post_thumbnail_id( $post ); |
16 | 295 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
296 |
if ( ! $post_thumbnail_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
297 |
return ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
298 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
299 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
300 |
$caption = wp_get_attachment_caption( $post_thumbnail_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
301 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
302 |
if ( ! $caption ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
303 |
$caption = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
304 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
305 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
306 |
return $caption; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
307 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
308 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
309 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
310 |
* Displays the post thumbnail caption. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
311 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
312 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
313 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
314 |
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
315 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
316 |
function the_post_thumbnail_caption( $post = null ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
317 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
318 |
* Filters the displayed post thumbnail caption. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
319 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
320 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
321 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
322 |
* @param string $caption Caption for the given attachment. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
323 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
324 |
echo apply_filters( 'the_post_thumbnail_caption', get_the_post_thumbnail_caption( $post ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
325 |
} |