Automatic SEO for
Images Using JavaScript
by: Keith
We all know that it's not that easy to optimize each and
every image on your blog site because of the time it consumes. So here's a
short snippet of JavaScript code that you can paste on your blog site that will
automatically add the necessary attributes on your images such as
"title", "alt", and the like so it can be optimized for
search engines. What's great about learn web design it is that it doesn’t just optimize your new
images but also the other images in your older posts as well.
Simply paste this code just BEFORE the </body> tag inside your blog
site’s HTML editor.
<script
src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js'
type='text/javascript'/>
<script
type='text/javascript'>
//<![CDATA[
$(document).ready(function()
{
$('img').each(function(){
var $img = $(this);
var filename =
$img.attr('src')
$img.attr('alt',
filename.substring((filename.lastIndexOf('/'))+1,
filename.lastIndexOf('.')));
});
});
//]]>
</script>
<script type='text/javascript'>
//<![CDATA[
$(document).ready(function()
{
$('img').each(function(){
var $img = $(this);
var filename =
$img.attr('src')
$img.attr('title',
filename.substring((filename.lastIndexOf('/'))+1,
filename.lastIndexOf('.')));
});
});
//]]>
</script>
|
Hit “Save” and you’re done!
By the way, this works for BOTH Blogger and WordPress.
No comments:
Post a Comment