Skip to content

Commit b97ff22

Browse files
committed
Updated to use Picture element
Now we're using the <picture></picture> element with a javascript pollyfill that supports down to IE9 with an IE8 fallback. Less code than the first version. Super cool
1 parent 4b935de commit b97ff22

File tree

4 files changed

+42
-45
lines changed

4 files changed

+42
-45
lines changed

js/borealis.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

js/pictureTime.js

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readme.txt

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,21 @@
22
Make Sure current theme has 'add_theme_support( 'post-thumbnails' );'
33

44

5-
This plugin adds 3 custom image sizes to your wordpress thumbnail function, and then uses the image id to generate a borealis responsive image tag using those three sizes.
5+
This plugin adds 3 custom image sizes to your wordpress thumbnail function, and then uses the image id to generate a pictureTime responsive image tag using those three sizes.
66

77
It works best with advanced custom fields. If you'd like to add more sizes, you can do so in the php file of this plugin.
88

99
Put following code wherever you'd like the image to be
1010

11-
<?php
12-
13-
$image = 'the image id';
14-
// here we define the specific image sizes and names to be used in borealis
15-
$mappings = array(
16-
0 => 'small-img', // zero maps to default
17-
500 => 'medium-img',
18-
800 => 'large-img'
19-
);
20-
echo '<img data-borealis-srcs="', getBorealisSrcs($image, $mappings), '">';
21-
22-
?>
23-
11+
<picture>
12+
<?php
13+
$image = 'the image id or ACF field name';
14+
$mappings = array(
15+
0 => 'small-img', // zero maps to default
16+
500 => 'medium-img',
17+
800 => 'large-img'
18+
);
19+
echo getPictureSrcs($image, $mappings);
20+
?>
21+
</picture>
2422

wp-tevko-responsive-images.php

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,39 @@
11
<?php
22

3-
/*
4-
Plugin Name: WP Tevko Responsive Images
5-
Plugin URI: http://timevko.com
6-
Description: Fully responsive image solution using Borealis and the ID of your image.
7-
Version: 0.0.1
8-
Author: Tim Evko
9-
Author URI: http://timevko.com
10-
License: Creative Commons
11-
*/
3+
/*
4+
Plugin Name: WP Tevko Responsive Images
5+
Plugin URI: http://timevko.com
6+
Description: Fully responsive image solution using pictureTime and the ID of your image.
7+
Version: 0.0.1
8+
Author: Tim Evko
9+
Author URI: http://timevko.com
10+
License: Creative Commons
11+
*/
1212

1313

14-
//first we get borealis
14+
//first we get pictureTime
1515

16-
function get_borealis() {
17-
wp_enqueue_script( 'borealis', plugins_url( '/js/borealis.js', __FILE__ ));
18-
}
16+
function get_pictureTime() {
17+
wp_enqueue_script( 'pictureTime', plugins_url( '/js/pictureTime.js', __FILE__ ));
18+
}
1919

20-
add_action('init','get_borealis');
20+
add_action('init','get_pictureTime');
2121

22-
//add support for our desired image sizes
23-
add_image_size( 'large-img', 1000, 702);
24-
add_image_size( 'medium-img', 700, 372);
25-
add_image_size( 'small-img', 300, 200);
22+
//add support for our desired image sizes
23+
add_image_size( 'large-img', 1000, 702);
24+
add_image_size( 'medium-img', 700, 372);
25+
add_image_size( 'small-img', 300, 200);
2626

27-
function getBorealisSrcs($image, $mappings)
27+
function getPictureSrcs($image, $mappings)
2828
{
2929
$arr = array();
3030

3131
foreach ($mappings as $size => $type)
3232
{
3333
$imageSrc = wp_get_attachment_image_src($image, $type);
34-
if ($size)
35-
{
36-
$arr[] = $size . ': ' . $imageSrc[0];
37-
}
38-
else
39-
{
40-
$arr[] = $imageSrc[0];
41-
}
34+
$arr[] ='<source srcset="'. $imageSrc[0] . ' "media="(min-width:'. $size .'px)"/>';
4235
}
43-
return implode(', ', $arr);
36+
return implode(array_reverse($arr));
4437
}
4538

4639
?>

0 commit comments

Comments
 (0)