0

I would like to use ENTER button to insert line break, not SHIFT + ENTER by default. I added this code into function.php. It works but the problem is the text-align buttons are not working. When I click on any text align button, nothing happens. The text align buttons in Both Wordpress editor and TinyMCE Advance plugin editor are not working. But when I remove the code, it comes back normal. How can I solve this issue?

 /* Filter Tiny MCE Default Settings */
 add_filter( 'tiny_mce_before_init', 'my_switch_tinymce_p_br' );
 /**
     Switch Default Behaviour in TinyMCE to use "<br>"
     On Enter instead of "<p>"
     @link https://shellcreeper.com/?p=1041
     @link http://codex.wordpress.org/Plugin_API/Filter_Reference/tiny_mce_before_init
     @link http://www.tinymce.com/wiki.php/Configuration:forced_root_block
 */
 function my_switch_tinymce_p_br( $settings ) {
     $settings['forced_root_block'] = false;
     return $settings;
 }
0

While i didn't exactly look into TinyMCEs code, my assumption is the following: Without using the above code, TinyMCE closes the active p-tag and opens another one on pressing Enter. When you use the above code, this is replaced by NOT opening any p-tags and just inserting
tags when you press Enter.

The Alignment-Buttons probably try to find the p-tag, which encase the current text and add an style-tag (text-align:left). As there is no p-tag, the style can not be added and the text-align buttons "do not work".

IF it is like this, there is no way of "repairing" this behaviour without pretty much editing TinyMCE.

  • I don't understand why they assign ENTER button to p-tag by default. It doesn't make sense because using enter button to make line break is common. And many people get used to this practice. To insert paragraph, you just press enter two times. And this is also common practice that people get used to. Yes, you can hit Shift+enter to get line break in this case BUT it's not common for people to do that and I am sure people know ENTER better than Shift+enter. I've tried to manage to go it but cannot. Seem to look easy to do, but hard. – Topy Aug 30 '17 at 15:45
  • Maybe because ALL of the Text-softwares Work that way? Word, OpenOffice writer, Apple Pages, Outlook, every single one of them Works Like this... – HU ist Sebastian Aug 30 '17 at 16:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.