0 レビュー
3 回答
php-ショートコード用のWPTinyMCE投稿エディタのカスタムボタン
Wordpressの投稿エディターのTinyMCEエディターで特別なボタンを作成しようとしています。作成したショートコードツールチップのボタンを作成したい。
希望する出力を確認してください:
ツールチップのショートコードに次のコードがあります:
//Text tooltip
function tooltip($atts, $content = ''){
$atts = shortcode_atts(
array(
'class' => '',
'title' => ''
), $atts);
$html = '<a class="' . $atts['class'] .'" title="'. $atts['title']. '" href="#">' . $content . ' <span>' .$atts['title']. '</span> </a>';
return $html;
}
add_shortcode('tooltip', 'tooltip');
これを実行するときは、ショートコードに次のコードを使用します。
[tooltips class="top_tooltip" title="Your Tooltip here"] Text here [/tooltip]
私が行ったことは、次のコードを使用して、テーマのfunctions.phpファイルに作成したカスタムボタンツールチップの短いコードを表示する関数を作成したことです。
//Create Tiny MCE buttons
function mce_tooltip($button) {
$buttons[] = 'superscript';
return $button;
}
add_filter('mce_buttons_2', 'mce_tooltip');
/*
* Callback function to filter the MCE settings
*/
function mce_tooltip( $init_array ) {
// Define the style_formats array
$style_formats = array(
// Each array child is a format with it's own settings
array(
'class' => '',
'title' => ''
);
// Insert the array, JSON ENCODED, into 'style_formats'
$init_array['style_formats'] = json_encode( $style_formats );
return $init_array;
}
// Attach callback to 'tiny_mce_before_init'
add_filter( 'tiny_mce_before_init', 'mce_tooltip' );
コードを試しましたが、WordpressのTINYMCEエディターにショートコードの[カスタム]ボタンが表示されません。それをより良くする方法はありますか?
わからない
0
レビュー
答え :
解決策:
コードを確認してください。無効な戻り値があると思います
function mce_tooltip($button) {
$buttons[] = 'superscript';
return $button;
}
わからない
0
レビュー
答え :
解決策:
TinyMCE Advancedバージョンの場合:4.1.1次の手順に従います:
- /wp-content/plugins/tinymce-advanced/tinymce-advanced.php(
function get_all_buttons()
)に$buttons[] = 'yourButton'
を追加します http://prntscr.com/5ywb4p - /wp-includes/js/tinymce/tinymce.min.jsで、ボタンの後に独自のボタンを追加します
e.addButton('yourButton',{title:'yourButton',text:"yourButton",'class' : 'yourButton-btn', onclick : function() { e.focus(); e.selection.setContent('<YourTag>' + e.selection.getContent() + '</YourTag>'); } })
http://prntscr.com/5ywc48 次に、wp-adminのtinymce設定に移動し、新しいボタンをエディターに追加します。
わからない
0
レビュー
答え :
解決策:
http://www.gavick.com/blog/adding-your-own-buttons-in-tinymce-4-editor/ >
このチュートリアルを試してみてください。うまくいきます。新しいTinymce4にカスタムボタンを追加する方法と、独自のショートコードに使用する方法を説明しています。
わからない
同様の質問
私たちのウェブサイトで同様の質問で答えを見つけてください。