Search code examples
wordpresslinefeed

How to break lines properly which contain both CJK and english characters in WordPress?


I found that CJK article in my wordpress4.7 can't break lines properly,which contain both CJK and english characters.
Here is the article before publish.

enter image description here

All the lines breaked properly before publish.

enter image description here

Now it displayed as below after published. All lines messed ,breaked bad-formatted as unexpected way.

enter image description here

I had tried to fix it this way.

vim  /var/www/html/wp/wp-content/themes/twentysixteen/style.css 
.site-inner {
    margin: 0 auto;
    max-width: 1320px;
    position: relative;
}

.site-content {
    word-wrap: break-word;overflow:hidden;
    word-break:break-all;white-space:pre-wrap;
}

To restart apache and wordpress,no effect at all.
My wordpress version is 4.7,theme is twentysixteen.


Solution

  • try to add this code in your functions.php theme file

        function my_tinymce_fix( $init )
        {
            // html elements being stripped
            $init['extended_valid_elements'] = 'div[*], article[*]';
    
            // don't remove line breaks
            $init['remove_linebreaks'] = false;
    
            // convert newline characters to BR
            $init['convert_newlines_to_brs'] = true;
    
            // don't remove redundant BR
            $init['remove_redundant_brs'] = false;
    
            // pass back to wordpress
            return $init;
        }
        add_filter('tiny_mce_before_init', 'my_tiny_mce_fix');