Placeholder for broken images

Nuno

Well-known member
Hello,

I hate to see posts with broken images, so I end up using a simple jquery script that I found in stackoverflow to replace the error image with a placeholder:

So, before </body> add:

Code:
<script>
jQuery("img.bbCodeImage").one('error', function () {
    jQuery(this).attr("src", "/styles/default/xenforo/placeholder.jpg");
}).each(function () {
    if (this.complete && !this.naturalHeight && !this.naturalWidth) {
        $(this).triggerHandler('error');
    }
});
</script>

Don't forget to upload the placeholder image to your server!

I placed this in the suggestion forum so this can be added to the default theme and because I don't have privileges to posts this in the tips section :)
 

Attachments

  • placeholder.webp
    placeholder.webp
    18.8 KB · Views: 21
Upvote 8
Back
Top Bottom