如何禁止wordpress url将`&`交换为`#038;`?

发布于 2024-10-31 17:43:12 字数 419 浏览 3 评论 0原文

我想在wordpress中通过url传递一些值,但是我遇到了一些问题,wordpress会自动将&交换为#038;,如何制作& ; 仍然是 & 吗?

我注意到在wp-includes/formatting.php中,有很多交换符号的规则,我尝试修改一些代码,但失败了。

某些链接(如

site.com?this=that&that=this)将输出到 Web 浏览器地址(如 site.com?this=that#038that=this

和页面无法获取that=this部分的值

如何正确设置?谢谢。

I want to pass some value through url in wordpress, but I met some trouble that wordpress will exchange & to #038; automatically, how to make a & still as a & ?

I noticed in wp-includes/formatting.php, there has many rules to exchange symbols, I tried modify some code, but failed.

some link like

site.com?this=that&that=this will output to the web browser address like site.com?this=that#038that=this

and the page can not get the value in the part that=this

how to setting correctly? thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

带上头具痛哭 2024-11-07 17:43:12

您可以通过将其添加到functions.php中来禁用wptexturize()文件放在模板文件夹中(或将其添加到现有文件夹中):

remove_filter('the_content', 'wptexturize');

但请注意,这当然会禁用所有“清理”,而不仅仅是“&”转换。

如果您希望去掉 & 符号转换,您可以在formatting.php 中注释第 962 行。我在下面发布了第 961 和 962 行(这是来自未更改的 WP 3.1):

// Converts lone & characters into & (a.k.a. &)  
$content = preg_replace('/&([^#])(?![a-z1-4]{1,8};)/i', '&$1', $content);

You can disable wptexturize() by adding this in a functions.php file inside your template folder (or add it to the existing one):

remove_filter('the_content', 'wptexturize');

But note that this will of course disable all the "cleaning", not just the '&' conversion.

If you prefer to just get rid of the ampersand conversion you can comment line 962 in formatting.php. I post lines 961 and 962 bellow (this is from an unaltered WP 3.1):

// Converts lone & characters into & (a.k.a. &)  
$content = preg_replace('/&([^#])(?![a-z1-4]{1,8};)/i', '&$1', $content);
鹿港巷口少年归 2024-11-07 17:43:12

我也遇到了这个问题,经过一番研究,我发现 这个插件 可以修复它。安装插件后,您只需在不希望 WordPress 格式化的代码周围添加这些标签即可。就像这样:

<!-- noformat on -->
Your code with & in it
<!-- noformat off -->

希望有帮助!

I also had this problem, after some research I found this plugin which fixes it. After installing the plugin you just add these tags around the piece of code you don't want wordpress to format. Like so:

<!-- noformat on -->
Your code with & in it
<!-- noformat off -->

Hope that helps!

故事未完 2024-11-07 17:43:12

另一个解决方案:

wp-includes\formatting.php:在 esc_url () 注释该行

$url = str_replace( '&', '&', $url );

它对我有用。

One More Solution:

wp-includes\formatting.php: in esc_url () comment the line

$url = str_replace( '&', '&', $url );

It works for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文