Skip to content

Commit d9a4615

Browse files
committed
Img alt tag functionality included!
This will change up the syntax needed to use via php in template files. If you upgrade but do not change syntax, plugin will still work, you just won't have alt tags
1 parent 60b91dc commit d9a4615

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

readme.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ This plugin tells WordPress to create three additional sizes for images you uplo
77

88
PHP (use in template files) -
99

10-
<span data-picture>
11-
<?php
12-
$image = 'the id of your image';
13-
$mappings = array(
14-
0 => 'small-img',
15-
250 => 'large-img',
16-
1000 => 'full-width'
17-
);
18-
?>
10+
<?php
11+
$image = get_field('upload_image');
12+
$mappings = array(
13+
0 => 'small-img', // zero maps to default
14+
250 => 'large-img',
15+
1000 => 'full-width'
16+
);
17+
?>
18+
<span data-picture data-alt="<?php echo get_img_alt($image) ?>">
1919
<?php echo getPictureSrcs($image, $mappings) ?>
2020
<noscript> <?php echo wp_get_attachment_image($image, $mappings[2]) ?> </noscript>
2121
</span>

wp-tevko-responsive-images.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
Plugin Name: WP Tevko Responsive Images
55
Plugin URI: http://timevko.com
66
Description: Fully responsive image solution using picturefill and the ID of your image.
7-
Version: 0.2.0
7+
Version: 0.2.2
88
Author: Tim Evko
99
Author URI: http://timevko.com
10-
License: Creative Commons
10+
License: MIT
1111
*/
1212

1313

@@ -24,12 +24,16 @@ function get_picturefill() {
2424
add_image_size('medium-img', 700, 372);
2525
add_image_size('small-img', 300, 200);
2626

27+
//alt tags will now be automatically included
28+
function get_img_alt($image) {
29+
$imgalt = trim(strip_tags( get_post_meta($image, '_wp_attachment_image_alt', true) ));
30+
return $imgalt;
31+
}
2732

2833
function getPictureSrcs($image, $mappings) {
2934
$arr = array();
30-
3135
foreach ($mappings as $size => $type) {
32-
$imageSrc = wp_get_attachment_image_src($image, $type);
36+
$imageSrc = wp_get_attachment_image_src($image, $type, $alt);
3337
$arr[] ='<span data-src="'. $imageSrc[0] . ' "data-media="(min-width:'. $size .'px)"></span>';
3438
}
3539
return implode($arr);
@@ -51,7 +55,7 @@ function responsiveShortcode($atts) {
5155
);
5256

5357
return
54-
'<span data-picture>'
58+
'<span data-picture data-alt="'. get_img_alt($imageid) .'">'
5559
. getPictureSrcs($imageid, $mappings) .
5660
'<noscript>' . wp_get_attachment_image($imageid, $size2) . ' </noscript>
5761
</span>';
@@ -67,4 +71,4 @@ function responsive_insert_image($html, $id, $caption, $title, $align, $url) {
6771
}
6872
add_filter('image_send_to_editor', 'responsive_insert_image', 10, 9);
6973

70-
?>
74+
?>

0 commit comments

Comments
 (0)