テキストエディタ の ショートカットボタン を カスタマイズ してみた
この記事は 2015年 8月 11日 に書かれた記事です。
この記事は WordPress Version 4.2.2 の時の記事です。
今回 テキストエディタ の ショートカットボタン を
カスタマイズしたので いろいろメモしておきたいと思います
まずは 投稿 の 場合のみ 標準で付いている ショートカットボタンを 削除する方法です
//---------------------------------------------------------------------------
// テキストエディタ : ショートカットボタン削除
//---------------------------------------------------------------------------
add_filter( 'quicktags_settings', function( $qtInit ) {
if( get_post_type() === 'post' ) {
$qtInit['buttons'] = ',';
}
return $qtInit;
}, 10, 1 );
次に 投稿 と 投稿ではない 場合で 条件を分けて
ショートカットボタンを 追加する方法です
//---------------------------------------------------------------------------
// テキストエディタ : ショートカットボタン追加
//---------------------------------------------------------------------------
add_action( 'admin_print_footer_scripts', function() {
if( wp_script_is( 'quicktags' ) && get_post_type() !== 'post' ) {
?>
<script>
// tag h2
QTags.addButton( 'jr_html_tag_h2', 'tag h2', '<h2>', '</h2>' );
</script>
<?php
} else {
?>
<script>
// 見出し(大)
QTags.addButton( 'jr_html_tag_h2_custom', '見出し(大)', '<h2>', '</h2>' );
</script>
<?php
}
} );