Skip to content

Instantly share code, notes, and snippets.

@rafaelcavalcante
Created March 8, 2017 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaelcavalcante/885b6b4356eaf8fb4cd495eaf757f175 to your computer and use it in GitHub Desktop.
Save rafaelcavalcante/885b6b4356eaf8fb4cd495eaf757f175 to your computer and use it in GitHub Desktop.
the_penck_thumbnail()
<?php
/*
PT: O snippet "penck thumbnail" foi feito para exibir
o caminho da imagem de acordo com o objeto de imagem retornado do
plugin Advanced Custom Fields
EN: The penck thumbnail snipper were made to output the
image path according to the image object returned by the
Advanced Custom Fields plugin
*/
add_image_size('blog-thumbnail-2x', 1920, 1080, array( 'center', 'center' ) );
add_image_size('blog-thumbnail-1x', 960, 540, array( 'center', 'center' ) );
function the_penck_thumbnail($fieldname, $size) {
$attachment_id = get_field($fieldname);
$url = wp_get_attachment_image_src( $attachment_id, $size )[0];
echo $url;
}
/*
USAGE
the_penck_thumbnail('the-image-field-name','the-size-to-show'); // http://github.com/blog/uploads/image.jpg
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment