WordPressでプラグインを使わずにエディタにクイックタグを追加する方法。


WordPressのエディタにクイックタグを追加する方法の紹介です。

functions.php に以下のように追記します。

<?php
new MyQuickTags();
class MyQuickTags {

    public function __construct() {
        add_action('admin_print_footer_scripts', array($this, 'add_tags'));
    }

    function add_tags() {
        ?>
        <script type="text/javascript">
            QTags.addButton('my_small', 'small', '<small>', '</small>');
        </script>
        <?php
    }

}
?>

クイックタグを追加する場合は、

スクリプトタグ内に以下のような形で追加していくだけです。

<script type="text/javascript">

QTags.addButton('任意のユニークなID', 'ラベル', '開始タグ', '終了タグ'); //これを追加

</script>

tag
上図のような感じで追加されます。

詳しくはQuicktags API « WordPress Codexをご覧下さい。

スポンサード リンク

公開日:2013年12月12日
タグ:,