-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresponsive-images.php
62 lines (53 loc) · 2.16 KB
/
responsive-images.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
<?php
/**
* Configure responsive images sizes
*
* @package WordPress
* @subpackage FoundationPress
* @since FoundationPress 2.6.0
*/
// Add featured image sizes
//
// Sizes are optimized and cropped for landscape aspect ratio
// and optimized for HiDPI displays on 'small' and 'medium' screen sizes.
add_image_size( 'featured-small', 640, 200, true ); // name, width, height, crop
add_image_size( 'featured-medium', 1280, 400, true );
add_image_size( 'featured-large', 1440, 400, true );
add_image_size( 'featured-xlarge', 1920, 400, true );
// Add additional image sizes
add_image_size( 'fp-small', 640 );
add_image_size( 'fp-medium', 1024 );
add_image_size( 'fp-large', 1200 );
add_image_size( 'fp-xlarge', 1920 );
// Register the new image sizes for use in the add media modal in wp-admin
function foundationpress_custom_sizes( $sizes ) {
return array_merge( $sizes, array(
'fp-small' => __( 'FP Small' ),
'fp-medium' => __( 'FP Medium' ),
'fp-large' => __( 'FP Large' ),
'fp-xlarge' => __( 'FP XLarge' ),
) );
}
add_filter( 'image_size_names_choose', 'foundationpress_custom_sizes' );
// Add custom image sizes attribute to enhance responsive image functionality for content images
function foundationpress_adjust_image_sizes_attr( $sizes, $size ) {
// Actual width of image
$width = $size[0];
// Full width page template
if ( is_page_template( 'page-templates/page-full-width.php' ) ) {
1200 < $width && $sizes = '(max-width: 1199px) 98vw, 1200px';
1200 > $width && $sizes = '(max-width: 1199px) 98vw, ' . $width . 'px';
// Default 3/4 column post/page layout
} else {
770 < $width && $sizes = '(max-width: 639px) 98vw, (max-width: 1199px) 64vw, 770px';
770 > $width && $sizes = '(max-width: 639px) 98vw, (max-width: 1199px) 64vw, ' . $width . 'px';
}
return $sizes;
}
add_filter( 'wp_calculate_image_sizes', 'foundationpress_adjust_image_sizes_attr', 10 , 2 );
// Remove inline width and height attributes for post thumbnails
function remove_thumbnail_dimensions( $html, $post_id, $post_image_id ) {
$html = preg_replace( '/(width|height)=\"\d*\"\s/', '', $html );
return $html;
}
add_filter( 'post_thumbnail_html', 'remove_thumbnail_dimensions', 10, 3 );