How to forbidden wordpress url exchange `&` to `#038;`?

独自空忆成欢 提交于 2019-12-24 01:47:22

问题


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.


回答1:


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);



回答2:


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!




回答3:


One More Solution:

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

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

It works for me.



来源:https://stackoverflow.com/questions/5605122/how-to-forbidden-wordpress-url-exchange-to-038

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!