2015-09-07 68 views
0

我想向高級自定義字段中的wysiwyg編輯器添加自定義按鈕。我還沒有找到解決方法。在高級自定義字段中將自定義樣式按鈕添加到wysiwyg

我想要的是一個按鈕,它將選定的文字包裝在<span class="someclass"></span>中,以便我可以按照自己的喜好設計它。

我如何做到這一點?

+0

http://stackoverflow.com/questions/18839252/add-custom-button-to-tinymce-in-wordpress – vard

+0

的可能的複製是U確保沒有與ACF這樣做的任何簡單的方式? – theva

+0

剛剛檢查ACF wysiwyg似乎你可以在acf wysiwyg工具欄上使用過濾器。請參閱http://www.advancedcustomfields.com/resources/customize-the-wysiwyg-toolbars/ – vard

回答

0

你需要做的是綁定到你的TinyMCE編輯器按鈕。這會爲該類的所見即所得編輯器添加一個格式下拉菜單。然後,您可以選擇您的文字並從下拉菜單中選擇課程。使用文本視圖來檢查它是否工作。

/* 
* Callback function to filter the MCE settings 
*/ 

// Callback function to insert 'styleselect' into the $buttons array 
function my_mce_buttons_2($buttons) { 
    array_unshift($buttons, 'styleselect'); 
    return $buttons; 
} 

// Register our callback to the appropriate filter 
add_filter('mce_buttons_2', 'my_mce_buttons_2'); 

function my_mce_before_init_insert_formats($init_array) { 
// Define the style_formats array 
    $style_formats = array(
     // Each array child is a format with it's own settings 
     array(
      'title' => 'Some Class', 
      'inline' => 'span', 
      'classes' => 'someclass' 
     ), 
    ); 
    // 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', 'my_mce_before_init_insert_formats'); 
相關問題