Currently browsing category: post thumbnail
SEO friendly timthumb on wordpress
Many of you love using timthumb in your wordpress theme but don’t use it because it does not generates seo friendly urls for images. I was asked by a client to make timthumb urls seo friendly and here is how I did that.
First open your wordpress site .htaccess file. Generally it is located in root of your wordpress installation.
It should look like this:
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
Now create new folder in your root call it let’s say images and place cache folder and timthumb in there then edit your .htaccess file as below
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(images) [NC]
RewriteRule . /index.php [L]
RewriteRule ^images/(.*)x(.*)/r/(.*) images/timthumb.php?src=http://example.com/$3&w=$1&h=$2&zc=1&q=100&a=tl
# END WordPress
Replace example.com with you site name:
Now upload htaccess file and where you need to use timthumb do as below
<?php
if (has_post_thumbnail()):
$thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
echo '<a href="'.get_permalink().'"><img alt="'.get_the_title().'" src="'.get_bloginfo('url').'/images/715x440/r/'.str_replace(array('http://example.com/', 'http://www.example.com/'), array('',''), $thumbnail[0]).'" width="715" height="440" /></a>';
endif;
?>
That should do the trick for making timthumb url seo friendly.
Getting post thumbnail
<?php
if (has_post_thumbnail()):
$thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
echo '<a href="'.get_permalink().'"><img src="'.get_bloginfo('template_url').'/timthumb.php? src='.$thumbnail[0].'&amp;w=715&amp;zc=1&amp;q=95&a=tl" width="715" alt="'.get_the_title().'" /></a>';
endif;
?>
<?php
if (has_post_thumbnail()):
$thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
?>
<a href="<?php echo $thumbnail[0];?>" class="modal"><img src="<?php bloginfo('template_url');?>/timthumb.php?src=<?php echo $thumbnail[0];?>&w=218&h=135&zc=1&q=95&a=tl" class="frame_img" /></a>
<?php endif;?>