Image Not Found

Nothing exists forever — including those images that you inserted in your blogposts from various external sources. Those who have been blogging for a long time now know the pain of such broken image links. Due to corrupt files, incorrect links, expired domains, deleted resources or whatever — your WordPress site can occasionally yield 404-errors on images — leading to negative SEO and poor reading experience.

One solution that exists — is to replace those image links with proper ones — which is a big headache.

But there exists a simple Javascript snippet which you can add into your site’s header and replace all broken images with a default one – in a jiffy.

[vcex_divider_dots color=”#dd3333″ margin_top=”10″ margin_bottom=”10″]

Let’s assume that the image that you want to use as replacement of broken images is located at /wp-content/uploads/2018/08/replace.png, you can add this Javascript to your WordPress blog’s header:

$('img').error(function(){
$(this).attr('src', '/wp-content/uploads/2018/08/replace.png');
});

If you don’t know how to do so, you can use a plugin like Header and Footer Scripts to insert your custom javascript arguments.

Alternatively, you can just place this PHP code snippet in your theme’s functions.php file, anywhere between <?php and ?> :

function imgReplace() { ?>
<script>
  $('img').error(function(){
$(this).attr('src', '/wp-content/uploads/2018/08/replace.png');
});
</script>
<?php }
add_action( 'wp_head', 'imgReplace' );

This is a totally safe practice and won’t do any harm if your site has no broken images at all.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

You May Also Like

10 Tips To Create An SEO-Friendly Website

Search engine optimization or SEO is getting recognition for promoting quality content and great practices. Your present website might look very cute, hip and fresh; however, if you don’t practice updated SEO standards, you might risk having little or no traffic at all. It would be a waste to invest all those resources in creating the best-looking website if your…

Hacked and Recovered

Due to some security irregularities and my carefree nature, gauravtiwari.org was hacked and spammed with negative SEO keywords. The hacking happened due to security loosening at Cloudflare and, continued to disturb the site for more than two weeks. Luckily, I had noticed it quite early and already started working on the fix. Before fixing, I made sure that the hack…

The Evolution of Internet Shopping

Whether you are a business owner, web designer or a consumer, it is helpful to recognize the trends and innovations in internet shopping. As a business owner, online marketing has become a key way to reach customers and generate income. As a web designer or business consultant, you must give your clients the best tools to meet their marketing needs.…

How can Google My Business Boost Your Local SEO?

Just “Google it.” If only I had a nickel every time I heard this phrase! Google has pretty much monopolized internet searching. And don’t let me dictate you into believing it — although I doubt this statement needs any proof. According to a report by NetMarketShare, Google alone accounts for more than 76 percent of online traffic. After all, when…

6 Web Design Tips to Boost Your Conversion Rate

It can be daunting to get more customers without conversions. Most business owners tend to focus on different aspects of digital marketing such as social media and SEO but invest little effort in their web design. Your design is the first thing that prospective customers will notice once they visit your website. They can use it to ascertain your degree…