Last active
June 12, 2017 10:27
-
-
Save gatespace/d4a199c87ce2ab4c1b82237a82f879c1 to your computer and use it in GitHub Desktop.
WordPress imgタグに独自のクラスや属性を追加する ref: http://qiita.com/gatespace/items/266142ce1dc84cb6f31c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
get_the_post_thumbnail( | |
$post, | |
$size, | |
array( | |
'class' => 'lazy', | |
'data-original' => 'img/example.jpg' | |
) | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
the_post_thumbnail( | |
$size, | |
array( | |
'class' => 'lazy', | |
'data-original' => 'img/example.jpg' | |
) | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
wp_get_attachment_image( | |
$attachment_id, | |
$size, | |
false, | |
array( | |
'class' => 'lazy', | |
'data-original' => 'img/example.jpg' | |
) | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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