WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] custom comment error page (10 posts)

  1. 2046
    Member
    Posted 7 years ago #

    hello,

    does anyone know how to make custom comment error page.
    Because when people don't fill all required fields in the comment form, they receive a page with WordPress logo and text such as "Error: please fill the required fields (name, email)."

    But not all of them understand that the system is based on WordPress and when they see the WordPress logo they are confused. They see any similarities with previous site.

    thanks for help jm

  2. lokjah
    Member
    Posted 7 years ago #

    I'm trying to find information on that as well, I'm wondering if theres a way to modify the 404 template to accommodate all of the possible errors, user and server?

  3. lokjah
    Member
    Posted 7 years ago #

    bump

    looking in comments-post.php which is the page that loads displaying the comment error, I dont see anywhere to customize that.

    and viewing the source of that page it has a reference to the wp-admin/install.css, it appears that the comment error is using a wp admin error page, have no idea if thats correct, but am also confused as to why its set up like it is.

  4. lokjah
    Member
    Posted 7 years ago #

    man this place is a ghost town. trying one last time

  5. kprensac
    Member
    Posted 6 years ago #

    This issue drove me crazy. It seems like it should be obvious. The answer, I think, is to edit /wp-includes/functions.php more or less between lines 1258 and 1275 (it s in a function called wp_die() )

  6. kevinobvious
    Member
    Posted 6 years ago #

    I didn't find an answer to this either so I made one. Using what kprensac said as a hint I started looking through wp-includes/functions.php and here's what I did.

    I inserted the following code inside the wp_die() function just before it starts outputting the html for the error page. Its two lines before the "<!DOCTYPE html PUBLIC" stuff. For me, I have version 2.3.1 which made the line number 1259 (I'm not sure about other versions of wordpress). Here's the code I added.

    $templatedir = get_template_directory();
    if ( file_exists($templatedir.'/die.php') ){
    	include($templatedir.'/die.php');
    	die();
    }

    This will check for a "die.php" file in your template directory and use that for the error page if it finds it. Otherwise, it will use the built in wordpress one.

    At some point inside the die.php file you will need to print the contents of the "$message" variable. That variable contains the actual error message.

    I ended up copying my single.php to die.php and edited things from there.

  7. kevinobvious
    Member
    Posted 6 years ago #

    One small "oops". The code above doesn't work for admin pages. If you wrap the above code in a "functions_exists" block you should be good to go:

    if (function_exists('get_template_directory')){
    	$templatedir = get_template_directory();
    	if ( file_exists($templatedir.'/die.php') ){
    		include($templatedir.'/die.php');
    		die();
    	}
    }
  8. stealthdave
    Member
    Posted 6 years ago #

    Thank you for saving me several hours of development time! Have you submitted this patch to the developers yet? It's very simple, clean, and addresses what is, in my opinion, one of WordPress' biggest weak points, error management. On an enterprise site, even a blog, younever want to see a default error message.

  9. kprensac
    Member
    Posted 6 years ago #

    Thank you Kevin for the excellent solution. I agree with Dave that this should be part of the core build.

  10. pauldm
    Member
    Posted 6 years ago #

    I am struggling to get this to work and cannot find a solution. I have copied the code as per above and have created a die.php file in my template directory (it is a direct copy of single.php with no amendments but I assume that does not matter - as long as there is a file to pull)

    I get a 500 internal server error. I can't understand why. Has anyone else had this problem? I am desperate for a solution as I thought it would be so easy to fix.

    I am running wordpress 2.3.3

    Many thanks

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags