概要説明
ChatGPTで作成された文章やオリジナルの処理を加えたいときに活用しています。本文内に任意のテキストを装飾用の表示に一括置換するカスタマイズ。
任意の文字をタグに変換したり、削除したりする
TAG1~TAG1 で囲まれたテキストを別のテキストに変換したり、装飾を加えたりするときに使用します
特定の文字に囲まれた場合の一括置換 例) **~**
functions.php
/*---------------------------------------------------- 管理画面以外の記事本文を任意の内容で一括置換して表示 ----------------------------------------------------*/ if ( !function_exists( 'replace_the_content' ) ){ if(!is_admin()) { function replace_the_content($content) { add_filter('the_content', function ($content) { $pattern = '/\*\*(.*)\*\*/u'; $replace = '<strong style ="color:red;">$1</strong>'; $content = preg_replace($pattern, $replace, $content); return $content; }, 10000); } } }
上記コードを加えることで指定の文字が太字の赤字タグに変換されて表示されるようになります