MyBB Community Forums

Full Version: Custom 404 Page Creation
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
reload the page and you will notice that the image change

Add this code to the last line on your .htaccess
ErrorDocument 404 /404.php
Create a file called 404.php, and add this to it:
   define('IN_MYBB', 1);

   add_breadcrumb("404 Error", $_SERVER['PHP_SELF']);

   eval("\$page = \"".$templates->get("404")."\";");

Upload the 404.php file to your main website's directory.
Create a new template on your main theme with the name 404 and add this to it:
<h1><center><a href="">Back Home</a></center></h1>
<h1><center>We couldn't find it.</center></h1>
<center>We couldn't find what you were looking for, double check your search.</center>
<script type="text/javascript">
  var imageURLs = [
     , ""
     , ""
     , ""
     , ""
     , ""
  function getImageTag() {
    var img = '<img src=\"';
    var randomIndex = Math.floor(Math.random() * imageURLs.length);
    img += imageURLs[randomIndex];
    img += '\" alt=\"Some alt text\"/>';
    return img;
<script type="text/javascript">


change the link to "Back Home"

Hope it was helpful
Tank you for you contribution.

One suggestion would be to cache the error template to save 1 query Toungue , like so:
$templatelist = "404";