How To add .bypostauthor attribute to WordPress comments

When I comment on my own blog, WordPress is supposed to automatically add the .bypostauthor attribute to my comment so that it can be styled via CSS to make it stand out from comments by other users. After recently exporting my blog from to self-hosted, I noticed that new comments were getting the .bypostauthor attribute, but older ones had nothing.

I spent quite a while searching online for help to no avail, so I decided to dig through the database on my web server. This is risky, because it is easy to make a complete mess of things if you don’t know what you are doing. I didn’t, but I pay for a backup service in case I ever need to restore things.

I opened my database using phpMyAdmin and browsed to the wp_comments table. I quickly discovered that recent comments I had made (which were getting the .bypostauthor attribute) had a user_id of 4. Older comments had a user_id of 0. I manually changed a couple of them from zero to four to see what would happen, and was pleasantly surprised to see the .bypostauthor attribute and CSS styling being added to my comments when I refreshed a blog page.

My next challenge was changing the 0 to 4 on all of my comments, which numbered close to a thousand. I started doing it manually, but quickly decided it would be too time-consuming. After searching online for SQL queries, I found something that worked.

UPDATE `wp_comments` SET `user_id` = '4' WHERE `comment_user_email` = 'authoremailaddress';

I entered this under the SQL tab of phpMyAdmin, made the necessary changes, and anxiously clicked Go. It worked!

Hopefully this will help someone in a similar situation. You will need to look under your wp_users table to see what the user_id is of your admin account first, then change the code above to reflect your user_id and your email address.

Good luck and be careful!

Author: Brian

Blogger. Bookworm. Michael Jackson fanatic. Lives in Kentucky with partner of 12 years and three fabulous felines.

Join the conversation!