SHARE
TWEET

MySql search and replace

Zeaks Jun 5th, 2011 226 Never
  1. When switching syntax highlighters this comes in handy to change the shortcode used in posts and comments. For example, changing [code lang="php"] to <pre lang="php">. You can add other languages, these are the only two I ever used.
  2.  
  3. Back up your database first!
  4.  
  5. Using phpMyAdmin, goto the SQL tab, and enter these lines one by one. (don't enter the description of each line)
  6.  
  7. For code in post content, this handles php, css and regular [code] tags without language added.
  8.  
  9. // changes post content from [code lang="php"] to <pre lang="php">
  10. UPDATE `wp_posts` SET `post_content` = replace(post_content, '[code lang="php"]', '<pre lang="php">')
  11.  
  12. // changes post content from [code lang="css"] to <pre lang="css">
  13. UPDATE `wp_posts` SET `post_content` = replace(post_content, '[code lang="css"]', '<pre lang="css">')
  14.  
  15. // changes post content from [code] to <pre>
  16. UPDATE `wp_posts` SET `post_content` = replace(post_content, '[code]', '<pre>')
  17.  
  18. // changes post content from [/code] to </pre>
  19. UPDATE `wp_posts` SET `post_content` = replace(post_content, '[/code]', '</pre>')
  20.  
  21.  
  22.  
  23. For code in comments, this handles php, css and regular [code] tags without language added.
  24.  
  25. // changes comments from [code lang="php"] to <pre lang="php">
  26. UPDATE `wp_comments` SET `comment_content` = replace(comment_content, '[code lang="php"]', '<pre lang="php">')
  27.  
  28. // changes comments from [code lang="css"] to <pre lang="css">
  29. UPDATE `wp_comments` SET `comment_content` = replace(comment_content, '[code lang="css"]', '<pre lang="css">')
  30.  
  31. // changes comment content from [code] to <pre>
  32. UPDATE `wp_comments` SET `comment_content` = replace(comment_content, '[code]', '<pre>')
  33.  
  34. // changes comment content from [/code] to </pre>
  35. UPDATE `wp_comments` SET `comment_content` = replace(comment_content, '[/code]', '</pre>')
RAW Paste Data
Top