Skip to content

Instantly share code, notes, and snippets.

@gatespace
Last active June 12, 2017 10:27
Show Gist options
  • Save gatespace/d4a199c87ce2ab4c1b82237a82f879c1 to your computer and use it in GitHub Desktop.
Save gatespace/d4a199c87ce2ab4c1b82237a82f879c1 to your computer and use it in GitHub Desktop.
WordPress imgタグに独自のクラスや属性を追加する ref: http://qiita.com/gatespace/items/266142ce1dc84cb6f31c
<?php
get_the_post_thumbnail(
$post,
$size,
array(
'class' => 'lazy',
'data-original' => 'img/example.jpg'
)
);
<?php
the_post_thumbnail(
$size,
array(
'class' => 'lazy',
'data-original' => 'img/example.jpg'
)
);
<?php
wp_get_attachment_image(
$attachment_id,
$size,
false,
array(
'class' => 'lazy',
'data-original' => 'img/example.jpg'
)
);
<?php
function my_attachment_image_attributes( $atts, $attachment ) {
$atts['class'] = $atts['class'] + ' lazy';
$atts['data-original'] = 'img/example.jpg';
return $atts;
}
add_filter( 'wp_get_attachment_image_attributes', 'my_attachment_image_attributes', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment