[WordPress] 見出しのレベルをまとめて1段階下げるSQL

スポンサーリンク
こんにちは。 雑食会社員🐼くま子です
スポンサーリンク

問題

もともとMarkdownで記載していて、普通に#=<h1>タグから記載していたのですが、
当ブログで使用している「cocoon」というテンプレートだと、
目次の位置や見出しのデザインなどからして、見出しは<h2>タグから始めた方が良さそうなので、一括で全ての目次のレベルを一段階下げることにした。

解決策

以下のSQLで一括置換

UPDATE wp_posts SET post_content=REPLACE(post_content, "<h6>", "<h7>") WHERE `post_content` LIKE "%<h1>%";
UPDATE wp_posts SET post_content=REPLACE(post_content, "<h5>", "<h6>") WHERE `post_content` LIKE "%<h1>%";
UPDATE wp_posts SET post_content=REPLACE(post_content, "<h4>", "<h5>") WHERE `post_content` LIKE "%<h1>%";
UPDATE wp_posts SET post_content=REPLACE(post_content, "<h3>", "<h4>") WHERE `post_content` LIKE "%<h1>%";
UPDATE wp_posts SET post_content=REPLACE(post_content, "<h2>", "<h3>") WHERE `post_content` LIKE "%<h1>%";
UPDATE wp_posts SET post_content=REPLACE(post_content, "<h1>", "<h2>") WHERE `post_content` LIKE "%<h1>%";
後から気がついたけどこの記事の見出しにh1を使っていた(ドジ)

コメント