个性化阅读
专注于IT技术分析

WordPress的帖子编辑器省略换行符吗?

在撰写WordPress帖子时, 在可视模式下会在文本编辑器中显示换行符, 但在HTML模式下只会出现&nbsp而不是BR标签。

如何在每个换行符处添加BR标签, 而不是默认情况下&nbsp?


#1


你可以在functions.php中使用这些代码来删除用于消除线路制动器的过滤器

remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );

function my_tinymce_config( $init ) {
    $init['remove_linebreaks'] = false; 
    $init['convert_newlines_to_brs'] = true; 
    $init['remove_redundant_brs'] = false; 
    return $init;
}
add_filter('tiny_mce_before_init', 'my_tinymce_config');

#2


你可以使用php的nl2br()函数。例如:

nl2br(get_the_content());

#3


如果要在Wordpress内容屏幕中添加换行符, 可以通过为<br />标签分配一个类来实现, 例如:

<br class="break" />

而Wordpress不会将其删除。

赞(0)
未经允许不得转载:srcmini » WordPress的帖子编辑器省略换行符吗?

评论 抢沙发

评论前必须登录!