I have recently started work on an existing WordPress site. The theme on the WordPress install uses TimThumb excessively, and it really is unnecessary. WordPress native image sizes should be able to handle the functionality required. However, I am not sure how to replace TimThumb.
There is a post-thumb.php
in the theme file that generates the thumbnails. The file is as follows:
if (get_option('solostream_default_thumbs') == 'yes') { $defthumb = get_bloginfo('stylesheet_directory') . '/images/def-thumb.jpg'; } else { $defthumb == 'false'; }
$solostream_img = get_the_image(array(
'meta_key' => 'thumbnail',
'size' => 'thumbnail',
'image_class' => 'thumbnail',
'default_image' => $defthumb,
'format' => 'array',
'image_scan' => true,
'link_to_post' => false, ));
if ( $solostream_img['url'] && get_option('solostream_show_thumbs') == 'yes' && get_post_meta( $post->ID, 'remove_thumb', true ) != 'Yes' ) { ?>
<img class="<?php echo $solostream_img['class']; ?>" src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php echo $solostream_img['url']; ?>&w=150&h=150&zc=1" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" />
<?php }
} ?>
I just want to replace this entire function with WordPress’ built in the_post_thumbnail('thumbnail')
function.
Is it as simple as replacing
src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php echo $solostream_img['url']; ?>&w=150&h=150&zc=1"
with something like
src="<?php the_post_thumbnail('thumbnail'); ?>"
Any ideas or a push in the right direction would be appreciated. Thanks for reading.
You can add custom thumbnails and use them within your code.
First you have to add theme support, set the thumbnail name, set the size, and set the size
You can then use this in your code by calling the following:
WordPress has a good reference page for this implementation and functions: https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
I’m not sure if it’s the most efficient way, but I have been able to get it working by replacing
with