Mar 03

Sample 404 Error Image

If you attempt to access the URL of a non-existent image file on a website – say a jpg, png or gif file – you will usually be redirected to the 404 error page. If the image is embedded via an HTML img tag, this will normally result in your browser displaying a missing image icon.

Instead, we can handle this in a more elegant way by creating a special 404 Error image which will be returned when someone attempts to request a non-existent image file on your website.

All we have to do is:

  1. Create the 404 Error Image file and save it in PNG format as “404.png”. Alternatively, you can use the one above.
  2. Upload the file to the images folder within your WordPress theme
  3. Your WordPress theme folder should have a file 404.php. This is the template file that is used to generate the 404 error page. Insert the following snippet of PHP code after the PHP opening tag at the very top of this file.
//If they have tried to access an invalid image file, return a 404 image
if ( preg_match( '~\.(jpe?g|png|gif|svg|bmp)(\?.*)?$~i', $_SERVER['REQUEST_URI']))
{
        $image404 = locate_template('images/404.png');
        if (!is_null($image404))
        {
                $fp = fopen($image404, 'rb');
                header( 'Content-Type: image/png' );
                header( 'Content-Length: ' . filesize($image404));
                fpassthru($fp);
        }
        exit;
}

Other Notes

The idea for this post was inspired by the following links:

Implement a 404 image in your Theme

The snippet of code they provided didn’t work for me, so I created my own.

http://wordpress.org/extend/plugins/wp-404-images-fix/

I haven’t tried this plugin, but if you don’t want to go to the trouble of modifying your theme files, this might provide a simpler alternative.

 

Tags:

Add Your Comments

css.php
  • https://faire-revenir-son-ex.com/sitemap.txt
  • https://everestgliders.com/sitemap.txt
  • https://behroo165.com/sitemap.txt
  • https://afftray.com/sitemap.txt
  • https://newsify.press/sitemap.txt
  • https://2bfoot.com/sitemap.txt
  • https://pantryz.com/sitemap.txt
  • https://nextgendataguru.com/sitemap.txt
  • https://wnewstv.com/sitemap.txt
  • http://i-park.org/sitemap.txt
  • https://10xtravel.com/sitemap.txt
  • https://edebiyatist.com/sitemap.txt
  • https://ytiyonkers.org/sitemap.txt
  • https://healthynights.co/sitemap.txt
  • https://3dmodely.ru/sitemap.txt
  • https://499football.com/sitemap.txt
  • https://admselenga.ru/sitemap.txt
  • https://ambia.ru/sitemap.txt
  • https://arteninaoltu.com/sitemap.txt
  • https://artislogistics.pro/sitemap.txt
  • https://artmama-mouse.ru/sitemap.txt
  • https://audit-research-center.com/sitemap.txt
  • https://avtoznak.ru/sitemap.txt
  • https://baikal-sera.ru/sitemap.txt
  • https://bethazor.com/sitemap.txt
  • https://bio7septic.ru/sitemap.txt
  • https://biotique-shop.ru/sitemap.txt
  • https://biserstav.ru/sitemap.txt
  • https://blowcamp.com/sitemap.txt
  • https://burger1.rest/sitemap.txt
  • http://wpsecure.be
  • http://wpskill.com
  • https://wpua.cloud
  • http://wresidencescostarica.com
  • https://wsportals.com
  • https://wssrradio.com
  • https://ws-start.ru
  • https://wyomingadvocates.com
  • http://wzonez.com
  • https://xanahosting.com
  • https://xcitercalls.com
  • https://xelbookings.com
  • https://xenvious.com
  • https://ximenamargain.com
  • http://xn--12cc2eo0ezb5as.com
  • http://xn--42cgaan6dxdxace0c1dg8cs4cu3n9fdh.com
  • http://xn--82cz5bqv8f.com
  • http://xn--thringen-verzaubert-69b.de
  • https://xrsw.uk
  • https://xsytikaa.com
  • https://yamaguchi-sokkyo.or.jp
  • https://yaminpublishing.com
  • https://yashhomes.ca
  • http://yellbitcoin.com
  • http://yestrading.net
  • https://yeungmarineholdings.com
  • https://yilsezklima.com
  • https://ymaa.pl
  • https://ymaaeurope.com
  • https://yogaineverydaylife.com
  • https://yogaworlds.in
  • http://yosoy.esy.es
  • http://youcalltheshots.net
  • https://youlooklovely.co
  • http://youlooklovely.photography
  • http://younkakura.com
  • https://yourroadstosuccess.com
  • https://youthfulandageless.com
  • https://yoyoriyu.com
  • https://ytiyonkers.org
  • https://yukomexico.com
  • https://yulehit.com
  • http://yusufyarar.com
  • http://yvonnevandermeer.nl
  • https://zabumutua.com
  • http://zakerhaghighi.ir
  • https://zakynthos2019.nl
  • https://zamacon.es
  • https://zbudujdom.net
  • https://zebiam.com