简体   繁体   English

如何将nl2br函数添加到文本小部件

[英]how to add nl2br function to text widget

I made my own theme. 我做了自己的主题。 Quite simple. 非常简单。 At the footer I add sidebar, which displays text widget. 在页脚处,添加了侧边栏,其中显示了文本小部件。 And it is working fine... until I have one line. 而且工作正常...直到我一行。

How to add to sidebar function, or how to modify content of the widget, to get function nl2br or something simillar - changing 'enter' to ' 如何添加到侧边栏功能,或如何修改小部件的内容,以获取功能nl2br或类似内容-将“输入”更改为“
'

Simple adding nl2br(dynamic_sidebar()) not working, also dynamic_sidebar(nl2br(..)); 简单添加nl2br(dynamic_sidebar())不起作用,dynamic_sidebar(nl2br(..));

I have try to add to my function.php code.. but I mess with something (probybly with $sidebar). 我尝试将其添加到我的function.php代码中。.但是我弄乱了某些东西(可能是$ sidebar)。

  add_filter('sidebar-1', 'newLines');

  function newLines($sidebar) {

  $sidebar = nl2br($sidebar);

  return $sidebar;

  }

You can use widget_text filter 您可以使用widget_text过滤器

function filter_text($text) {
    return nl2br($text);
}
add_filter('widget_text', 'filter_text');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM