How to fix missing or broken images in WordPress?

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 to your site’s header and replace all broken images with a default one – in a jiffy.

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.

If you don’t want to do this manually, there is a plugin that can help you do the same and more.

Plcehodor (https://wordpress.org/plugins/placehodor/) can substitute / replace missing images by a default image.

81e3110a fe31 4b25 b872 2891fa24e23a
0231e6aa c859 4e71 823a c12a7d23871c

First time here? Try these resources...

  1. Best VPN Services
  2. Best WordPress Hostings
  3. Best WordPress Themes
  4. Best WordPress Plugins
  5. Best Gutenberg Block Plugins
  6. Best Email Marketing Plugins
  7. Best WordPress Caching Plugins
  8. Best WooCommerce Plugins
  9. Email Marketing Guide for Beginners
  10. Best Small Business Apps
  11. Best Business Name Generators
  12. Top Plagiarism Checkers
  13. Free Web Hosting Services
  14. Best Online Businesses to Start
  15. Best Online Course Platforms
  16. Best Online Casinos in India
  17. Best Affiliate Marketing Programs
  18. More Resources...

Want to start blogging today? I personally use and recommend Bluehost.

Get useful blogging, marketing and learning resources, delivered to your mailbox. Plus, get regularly updated with extra tools & guides to help you learn, grow and earn better.

Get 17+ exclusive e-books & templates for free, to begin with. 🎁

%d bloggers like this: