Skip to content

Instantly share code, notes, and snippets.

@gormus
Created January 8, 2020 21:42
Show Gist options
  • Save gormus/ea2d91ac27931063caf9feb3598799f9 to your computer and use it in GitHub Desktop.
Save gormus/ea2d91ac27931063caf9feb3598799f9 to your computer and use it in GitHub Desktop.
Update WordPress posts which may contain broken code snippets for syntax highlighting.
-- 1. Reset all code snippets to use '<pre><code>' as opening tags.
UPDATE wp_posts
SET post_content = REGEXP_REPLACE(post_content, '<pre[^>]*>(<code[^>]*>)*', '<pre><code>')
WHERE post_status = 'publish'
AND post_type = 'post'
AND post_content RLIKE '<pre[^>]*>(<code[^>]*>)*';
-- 2. Reset all closing tags.
UPDATE wp_posts
SET post_content = REGEXP_REPLACE(post_content, '(<\/code>)*<\/pre>>', '</code></pre>')
WHERE post_status = 'publish'
AND post_type = 'post'
AND post_content RLIKE '(<\/code>)*<\/pre>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment