WordPress:从短代码中删除#038(WordPress: remove #038 from shortcode)

编程入门 行业动态 更新时间:2024-10-22 16:51:39
WordPress:从短代码中删除#038(WordPress: remove #038 from shortcode)

短代码的简单示例:

function s_print( $atts ){ return 'http://abc.com/?foo=1&bar=2'; } add_shortcode( 'my_shortcode', 's_print' );

它返回:

http://abc.com/?foo=1&bar=2

此函数通过短代码[my_shortcode]插入到页面正文的链接,但是&总是更改为&#038 ,这会破坏链接(它不再起作用)。 我google了很多。 有一些解决方案:

wp_specialchars_decode($foo); remove_filter('the_content','wptexturize');

但这些似乎仅用于主题(functions.php),它不适用于短代码(我尝试在短代码函数之前或之内添加它)。

我不想落到最后的解决方案,这是在WordPress formatting.php文件中注释一些行,因为我正在处理一个将被许多人使用的插件。

Simple example of a shortcode:

function s_print( $atts ){ return 'http://abc.com/?foo=1&bar=2'; } add_shortcode( 'my_shortcode', 's_print' );

And it returns:

http://abc.com/?foo=1&bar=2

This function inserts a link to page's body via shortcode [my_shortcode], but & is always changed to &#038, and this breaks the link (it's not working anymore). I googled a lot. There are some solutions:

wp_specialchars_decode($foo); remove_filter('the_content','wptexturize');

But those seems to be only for use in theme (functions.php) and it doesn't work for a shortcode (I tried adding it before or inside the shortcode function).

I don't want to fall to last solution, which is commenting some lines in WordPress formatting.php file because I'm working on a plugin which will be used by many people.

最满意答案

我有一个类似的问题,我用clean_url过滤器解决了。 请在此处查看我的答案中的编辑。

它不是短代码,所以我不能保证它会在你的特定情况下工作。 可能值得一试。

oyatek 编辑 (来自链接的修改后的解决方案):

function so_handle_038($content) { $content = str_replace(array("&","&"), "&", $content); return $content; } add_filter('the_content', 'so_handle_038', 199, 1);

I had a similar problem that I addressed with the clean_url filter. See the edit on my answer here.

It wasn't in a shortcode, so I can't guarantee it'll work in your particular situation. Might be worth a shot though.

EDIT by oyatek (modified solution from the link aboove):

function so_handle_038($content) { $content = str_replace(array("&","&"), "&", $content); return $content; } add_filter('the_content', 'so_handle_038', 199, 1);

更多推荐

本文发布于:2023-08-07 00:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1458453.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代码   WordPress   shortcode   remove

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!