Upon trying to achieve XHTML 1.0 Strict, one of the thing i found out that i had been doing wrong all this while is that i put target=”_blank” HTML tag in most of my post link, this is not a valid XHTML for Strict and it won’t pass the validation, but i had been doing this since the very first day i blog! It will be troublesome if i’m going to search for every post and take away the target=”_blank”!! So i guess the only way to do this easily is by using the MySQL query, i went to Google around and found this very useful SQL query in Lorelle’s blog.
Before proceed to make any changes to your WordPress database, it’s always a good idea that you backup your database first, who know you might missed out something and screw up your database, it’s always better to prevent than cure right? ๐
Continue with the search and replace, in order to do search and replace in WordPress database, you can use the REPLACE syntax in SQL query, the full line would like the following:
UPDATE wp_posts SET post_content = REPLACE (
post_content,
'Item to replace here',
'Replacement text here');
Where wp_posts is your WordPress database post table and post_content is your post content table field, most of the time you don’t need to change this two value.
The thing you need to change is obviously the Item to replace here, which is the text you want to search, it can be multiple string as long as the string is within the single quote, and Replacement text here is the text you want to replace, also can be multiple string as long as it’s within the single quote.
So in my case, i want to strip away target=”_blank” and replace it with nothing, so i do this:
UPDATE wp_posts SET post_content = REPLACE (
post_content,
' target="_blank"',
'');
Note that the i didn’t put anything for replace string, because i want to delete target=”_blank”, it’s a two single quote.
Again i would like to say, it’s a good practice that you backup your database always, once you screw up your database there is no turning back, and i will take no responsibility if something happen to your database, so do this at your own risk! ๐