Skip to content

Commit

Permalink
Add back compatability shim for data-sizes at all times.
Browse files Browse the repository at this point in the history
This comes after reverting 0163649 since we have to transform data-sizes attributes
no matter which version of WP is installed. Since this filter uses a simple `str_replace()`
instead of a preg_match, it's probably cleaner to add a separate filter than trying to
piggyback on our `wp_make_content_images_responsive()` filter, and the performance should be
similar either way.
  • Loading branch information
joemcgill committed Nov 5, 2015
1 parent f67e529 commit dcb6262
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions wp-tevko-responsive-images.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,20 @@ function tevkori_get_picturefill() {
wp_enqueue_script( 'picturefill', plugins_url( 'js/picturefill.min.js', __FILE__ ), array(), '3.0.1', true );
}
add_action( 'wp_enqueue_scripts', 'tevkori_get_picturefill' );

/**
* Back compatability shim for 'data-sizes' attributes in content.
*
* Prior to version 2.5 a 'srcset' and 'data-sizes' attribute were added to the image
* while inserting the image in the content. We replace the 'data-sizes' attribute by
* a 'sizes' attribute.
*
* @since 3.0.0
*
* @param string $content The content to filter;
* @return string The filtered content with `data-sizes` repaced by `sizes` attributes.
*/
function tevkori_replace_data_sizes( $content ) {
return str_replace( ' data-sizes="', ' sizes="', $content );
}
add_filter( 'the_content', 'tevkori_replace_data_sizes' );

0 comments on commit dcb6262

Please sign in to comment.