Created
July 4, 2013 04:26
-
-
Save lunaroja/5924922 to your computer and use it in GitHub Desktop.
Wordpress: Get post thumbnail URLs as data attributes
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
// use inside the loop | |
// <div <?php post_class() ?> <?php post_thumbnail_data_attributes(); ?>> | |
// data-thumbnail-large="http://url.com/wp-content/uploads/2013/07/chicago-1000x703.jpg" | |
// data-thumbnail-medium="http://url.com/wp-content/uploads/2013/07/chicago-500x351.jpg" | |
function post_thumbnail_data_attributes() { | |
$thumbnail_id = get_post_thumbnail_id(); | |
$thumbnail_large = wp_get_attachment_image_src($thumbnail_id, 'large'); | |
$data_attributes = ' data-thumbnail-large="' . $thumbnail_large[0] .'" '; | |
$thumbnail_medium = wp_get_attachment_image_src($thumbnail_id, 'medium'); | |
$data_attributes .= ' data-thumbnail-medium="' . $thumbnail_medium[0] .'" '; | |
echo $data_attributes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment