Deutsch English
WordPress Diesen Artikel auf Deutsch lesen

Blank page after commenting on a WordPress post

This issue is certainly known to a few, and I too have had the problem for a while that I couldn’t leave any comments on my own blog when logged in as admin (I could comment only from the back end, but not from the website). Today I have finally taken the “time” to go to the root of the problem. I am writing this in quotes, because in the end it didn’t take me three minutes to find the error. If only I had started searching much earlier. ;)

The problem was a missing hidden input in the comment form, which is required by WordPress:

<input type="hidden" name="comment_post_ID" value="<?php echo $post->ID; ?>" />

So if you constantly get a blank page after submitting a comment, you should check your comments template (usually that’s the file comments.php in the directory of your theme) to see if this line has been forgotten or inserted at a wrong place.

In my case, for example, I had inserted the line in the wrong place inside an if statement:

<?php if ( $user_ID ) : ?>
	<p>You are logged in as ...</p>
<?php else : ?>
	[Form fields for name, email etc.]
	<input type="hidden" name="comment_post_ID" value="<?php echo $post->ID; ?>" />
<?php endif; ?>

Thus the line was present for not logged-in visitors (guests), so they could comment without any problems. However, if you were logged in (which I, as the admin, of course always was), the line was missing, and if it’s missing, WordPress exits its comment script with a blank page without comment (haha!).
Correctly, it has to be like this of course:

<?php if ( $user_ID ) : ?>
	<p>You are logged in as ...</p>
<?php else : ?>
	[Form fields for name, email etc.]
<?php endif; ?>
<input type="hidden" name="comment_post_ID" value="<?php echo $post->ID; ?>" />

This way, the line is displayed in all cases, and then it also works as an admin!



Comments

  1. 21st January 2010
    8:30 pm

    Huken flag

    Thanks for this post! :)

Write comment

Allowed HTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <p> <pre lang="" line="" escaped=""> <q cite=""> <strike> <strong> <img src="" alt="" class="" width="" height=""> | Code snippets can be posted in `backticks`. Example: `<?php echo "Hi!"; ?>`