-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions-display.php
71 lines (57 loc) · 2.11 KB
/
functions-display.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
<?php
/**
* Functions for displaying images within a <picture> tag.
*
* @package Respect_Art_Direction
*/
/**
* If a post thumbnail is requested for a source set, display a <picture> tag.
*
* @param string $html The post thumbnail HTML.
* @param int $post_id The post ID.
* @param string $post_thumbnail_id The post thumbnail ID.
* @param string|array $size The post thumbnail size. Image size or array of width and height
* values (in that order). Default 'post-thumbnail'.
* @param string $attr Query string of attributes.
*
* @return mixed
*/
function rad_post_thumbnail_html( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
if ( ! rad_image_size_is_image_source( $size ) ) {
return $html;
}
return rad_the_post_thumbnail_with_art_direction( $post_thumbnail_id, $size );
}
add_filter( 'post_thumbnail_html', 'rad_post_thumbnail_html', 10, 5 );
/**
* Display an image with art direction.
*
* @param sting|int $image_id Image ID.
* @param string $source_name Source set size.
*
* @return string Image HTML markup.
*/
function rad_the_post_thumbnail_with_art_direction( $image_id, $source_name = '' ) {
global $rad_source_lists;
$html_tags = array(
'<picture>'
);
foreach ( $rad_source_lists[ $source_name ] as $breakpoint => $size ) {
$sources = array();
$breakpoint_info = rad_get_breakpoint( $breakpoint );
foreach ( $size as $current_size ) {
$image_src = wp_get_attachment_image_src( $image_id, $current_size );
$sources[] = $image_src[0] . ' ' . $image_src[1] . 'w';
}
$html = '<source';
if ( ! empty( $breakpoint_info ) ) {
$html .= ' media="' . esc_attr( $breakpoint_info ) . '"';
}
$html .= ' srcset="' . implode( ', ', $sources ) . '" />';
$html_tags[] = $html;
}
$default = wp_get_attachment_image_src( $image_id, 'custom1_default_size' );
$html_tags[] = '<img src="' . $default[0] . '" alt="Detail of the above quilt, highlighting the embroidery and exotic stitchwork." />';
$html_tags[] = '</picture>';
return implode( "\n", $html_tags );
}