Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace CKEditor toolbar images with font awesome icons

Is there some way to replace the default toolbar images (e.g. Bold, Italic, etc.) with Font Awesome icons?

like image 857
Daniel Avatar asked Oct 14 '25 15:10

Daniel


1 Answers

I know this is an old issue, but on a plugin by plugin basis I've been able to add font-awesome icons to ckeditor buttons with the following code inside the plugin's init function. In my case my plugin was called trim:

//Set the button name and fontawesome icon
var button_name = 'trim';
var icon = 'fa-scissors';

//When a ckeditor with this plugin in it is created, find the button
//in the current instance and add the fontawesome icon
CKEDITOR.on("instanceReady", function(event) {
  var this_instance = document.getElementById(event.editor.id + '_toolbox');
  var this_button = this_instance.querySelector('.cke_button__' + button_name + '_icon');
  if(typeof this_button != 'undefined') {
    this_button.innerHTML = '<i class="fa ' + icon + '" style="font: normal normal normal 14px/1 FontAwesome !important;"></i>';
  }
});

It hinges on knowing the class of the span inside the button, so it might not be the most convenient but it works.

like image 160
FellowSolicist Avatar answered Oct 17 '25 06:10

FellowSolicist



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!