如何防止破折号自动转换为&nDASH;

时间:2012-07-31 作者:radman

当我将--放入帖子时,它会自动转换为–– wordpress输出中的字符。

我怎样才能恢复正常\'--\' 我的内容中有双破折号。

4 个回复
SO网友:TheDeadMedic

在您的functions.php:

remove_filter( \'the_content\', \'wptexturize\' );
同样适用于the_excerptthe_title (如果需要)。

SO网友:Manuel

我找到了一个解决方案:如果您使用WordPress,请在文件的开头single.php 添加以下行:

<?php
remove_filter( \'the_title\', \'wptexturize\' );
remove_filter( \'the_content\', \'wptexturize\' );
remove_filter( \'the_excerpt\', \'wptexturize\' );
?>
然后做你的测试。我99.99%确信这会起作用,因为我也遇到了同样的问题,我在10秒前用这句话修复了它

SO网友:Nguyen Van Vinh

替代原点函数的另一个解决方案wptexturize 并更新所有相关筛选器。

define(\'EXCERPT_RARELY_2\', \'{[2}]\');
function wptexturize_custom($text = \'\')
{
    $text = preg_replace(\'!(^|[^\\-])\\-\\-([^\\-]|$)!\', \'$1\' . EXCERPT_RARELY_2 . \'$2\', $text);

    // get through origin filter
    $text = wptexturize($text);

    return str_replace(EXCERPT_RARELY_2, \'--\', $text);
}

// remove default filter
remove_filter(\'the_content\', \'wptexturize\');

// add custom filter
add_filter(\'the_content\', \'wptexturize_custom\');

// remove default filter
remove_filter(\'the_excerpt\', \'wptexturize\');

// add custom filter
add_filter(\'the_excerpt\', \'wptexturize_custom\');

SO网友:Laura F.

我遇到了与OP相同的问题,@TheDeadMedic提出的解决方案几乎对我有效。但是我的WP版本有几个功能。php文件,我必须将其添加到所有文件中(确保添加它们)after php开头代码<;?php):

remove_filter( \'the_title\', \'wptexturize\' );
remove_filter( \'the_content\', \'wptexturize\' );
remove_filter( \'the_excerpt\', \'wptexturize\' );
当然,如果您只想删除标题、内容或摘录的过滤器,那么只需要其中一个。

结束

相关推荐

Similar posts formatting

我正在使用类似的帖子插件http://wordpress.org/extend/plugins/similar-posts/, 我希望类似的帖子显示在同一行,而不是列表。。。如链路1、链路2、链路3、链路4而不是链接1链接2链接3链接4几天前,我在wordpress论坛和插件的官方网站上发布了这篇文章,但仍然没有答案。。。救救我!(我对编码知之甚少,所以请尽量具体,如果你给我代码,请解释每一行的作用,以便我可以学习)谢谢补充信息:我正在使用插件的大部分默认设置,我认为我所做的唯一更改是将其设置为只考虑标签