Created
April 3, 2013 09:59
-
-
Save cfenzo/5299919 to your computer and use it in GitHub Desktop.
How to replace timthumb with wordpress thumbnails for attachment-images in wordpress themes..
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
// add the thumbnail-sizes you need in functions.php | |
if ( function_exists( 'add_image_size' ) ) { | |
// repeat for all the thumbnail-sizes you need | |
add_image_size( 'thumb790x450', 790, 450, true ); | |
} | |
// helper-function for getting the attachemnt-ID from source. You need this when you only have an image-src | |
function get_attachment_id_from_src ($image_src) { | |
global $wpdb; | |
$query = "SELECT ID FROM {$wpdb->posts} WHERE guid='$image_src'"; | |
$id = $wpdb->get_var($query); | |
return $id; | |
} |
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
/* in any theme/plugin-file where timthumb is used */ | |
// If you only have the url (here named $src), use get_attachment_id_from_src | |
$photoID = get_attachment_id_from_src($src); | |
// When you have the attachment-id (here named $photoID): | |
$thisthumb = wp_get_attachment_image_src( $photoID,"thumb790x450"); | |
$thisthumb = $thisthumb[0]; | |
echo '<img src="$thisthumb" />'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment