I just resolved a problem on my WordPress blog where anytime a person posted a comment (logged in or not), they got a blank page. I tried all sorts of stuff to fix it. Turned off all the plugins, changed themes, you name it. I quickly discovered that when the comment form was submitted, none of the form variables were available in the wp-comments-post.php script. When this happens, the post can’t be queried from the DB and you fail on Line 11 (comment_id_not_found). A quick bit of debug code and I found NONE of the form variables were in $_POST. Not good.
I figured maybe something was in the theme headers, etc so I created a simple form with a couple variables that would post to wp-comment-post.php and it worked. Hmm. So I tried the other angle and created a comment post test script that dump the form variables and called it from my theme form file. The variables disappeared. Any theme, the variables vanished in my test script.
This had me totally confused. Why couldn’t I get basic form data into my form. Google returned a variety of ideas, but none that worked. Finally, I stumbled across a ticket for WordPress searching for ‘Blank Page on comments’ and someone had the same problem I did and for the same reason. It’s a doozy.
I’m one of those people who find the ‘www’ in URLs redundant. All my sites support them both, but from an SEO point of view, I’ve started ensuring www.mydomain.com permanently redirects to mydomain.com. When I setup this blog a few years ago, I had put in ‘www.baptiste.us’ in the blog configuration. A few months ago, I added a permanent redirect for www.baptiste.us to always go to baptiste.us. Everything worked as far as I could tell and since I don’t comment on my blog except to respond to new comments, well… That redirect and the blog settings BROKE the comments and I didn’t realize it for quite a while (I just figured nobody had anything to say
). Here’s why.
In WordPress theme comment files, the form ‘action’ variable includes the site url in front of wp-comments-post.php. So for my comment form, the action was set to http://www.baptiste.us/wp-comments-post.php, regardless of the theme I used. The problem is, the Permanent Redirect from www.baptiste.us to baptiste.us WIPES OUT the form variables, even though everything else seems to work. Silently. Now this may be due to session conflicts, etc, I’m not 100% sure.
But the solution was easy. I took out the ‘www.’ in my blog’s config so comment posts went to the ‘baptiste.us’ domain right away instead of www.baptiste.us and comments started working again.
Moral of the story - if you have a permanent redirect setup for your WordPress blog, be sure the desired domain is the domain set in the WordPress config. If you want everyone to end up at www.mydomain.com, you better have the ‘www’ in your WordPress config. If you want the www to always go away, make sure it’s not in your config either. Hopefully this post saves someone else the time and aggravation if they stumble into this trap.
So 3 days and nights of debugging on and off and all it took was updating two config variables in WordPress. Problem solved