最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

tinymce - Remove empty lines ( ) when author updates their post

programmeradmin4浏览0评论

Whenever adding an empty line between paragraphs using TinyMCE, the   character entity is added.

How can I strip the content of all instances of this character whenever an author updates their post (save_post)?

Whenever adding an empty line between paragraphs using TinyMCE, the   character entity is added.

How can I strip the content of all instances of this character whenever an author updates their post (save_post)?

Share Improve this question asked Mar 12, 2014 at 16:05 Christine CooperChristine Cooper 8,8977 gold badges60 silver badges93 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 7

Figured it out, hooking into content_save_pre:

function remove_empty_lines( $content ){

  // replace empty lines
  $content = preg_replace("/ /", "", $content);

  return $content;
}
add_action('content_save_pre', 'remove_empty_lines');

I liked your solution but it might happen to be that the " " is legit or intended in some part of the content further down in the content structure. The problem - at least for me - only occurs for the unnecessary and annoying extra lines at the beginning of the content. So I decided to extend your solution by only removing the extra "nonBreakingSpaces" at the very beginning of the text before any further tags occur:

function remove_empty_lines( $content ){

  // replace empty lines
$contentArr = explode('<',$content,2);
if (count($contentArr)==2) // only then  
{ 
    $contentArr[0] = preg_replace("/&nbsp;/", "", $contentArr[0]);
    $content = $contentArr[0].'<'.$contentArr[1]; 
}  
return $content;
}
add_action('content_save_pre', 'remove_empty_lines');
发布评论

评论列表(0)

  1. 暂无评论