Skip to content

Instantly share code, notes, and snippets.

@eclarrrk
Last active June 29, 2017 18:50
Show Gist options
  • Save eclarrrk/d5bb8ea059530bf759d3a8aa016416bd to your computer and use it in GitHub Desktop.
Save eclarrrk/d5bb8ea059530bf759d3a8aa016416bd to your computer and use it in GitHub Desktop.
// Add additional image size.
// First parameter is name for image size. Second parameter is the image's width. Height is set proportionally
// After this is added to functions.php, when an image is uploaded, an additional image with the width of the size entered will be created, but will not appear in the media library. much like thumbnail images are.
// Only applys to images uploaded since this code is added. Use regenerate thumbnails plugin to apply this change to all media.
add_image_size('x-large-img', 1300);
/////////////////////////////////////////////////
// Image tag calling an image's custom size URL.
// Line 18, First parameter is the image's ID
// Line 18, Second parameter is the name of the image size.
// Default size values are 'thumb' (150), 'thumbnail' (150), 'medium' (300), 'large' (1024), and 'full' (uploaded dimensions).
// Lines 19-20. No touchy!
<img src="<?php
$thumbnail_url = wp_get_attachment_image_src('$image_id', 'x-large-img', true );
$thumbnail_url = $thumbnail_url[0];
echo ( !empty($thumbnail_url) ) ? $thumbnail_url : 'No thumb!';
?>" alt="">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment