短代码的简单示例:
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]插入到页面正文的链接,但是&总是更改为& ,这会破坏链接(它不再起作用)。 我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=2This function inserts a link to page's body via shortcode [my_shortcode], but & is always changed to &, 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);更多推荐
发布评论