1,106 views
この記事は最終更新から 1489日 が経過しています。
1. やりたいこと
WORDPRESSの投稿中で、指定区間だけ > を ;gt に変換したい。
2. やってみる
1) ショートコード用プラグインを書く。
<?php /* Plugin Name: MyPre */ if (class_exists('MyPre')) { $gMyPre = new MyPre(); } class MyPre { ////////////////////////////////////////////////////////////////////////////// public function __construct() { // ショートコードを追加 add_shortcode('myPre', array($this, 'proc')); // テキストウィジェットの中でショートコードを実行可能に設定 add_filter('widget_text', 'do_shortcode'); } ////////////////////////////////////////////////////////////////////////////// public function proc( $attr, $content=null ){ $txt = preg_replace("/<br \/>/i", "", $content); $txt = preg_replace("/^\n/", "", $txt); $txt = esc_html($txt); $txt = preg_replace("/\n/", "<br />", $txt); return <<< EOM <div style="border:3px #000 dotted; padding:3px;">{$txt}</div> EOM; } }
2) ワードプレスの投稿中でショートコードを使う。
実行結果はこちら↓↓↓
>>>
>>>
AAAAA
BBBBB
>>>
AAAAA
BBBBB
出力されたコードはこちら↓↓↓