Rom*_*man 0 wordpress special-characters shortcode
简短代码的简单示例:
function s_print( $atts ){
return 'http://abc.com/?foo=1&bar=2';
}
add_shortcode( 'my_shortcode', 's_print' );
Run Code Online (Sandbox Code Playgroud)
它返回:
http://abc.com/?foo=1&bar=2
Run Code Online (Sandbox Code Playgroud)
此函数通过短代码插入到页面正文的链接[my_shortcode],但&总是更改为&,这会破坏链接(它不再起作用).我google了很多.有一些解决方案:
wp_specialchars_decode($foo);
remove_filter('the_content','wptexturize');
Run Code Online (Sandbox Code Playgroud)
但这些似乎仅用于主题(functions.php),它不适用于短代码(我尝试在短代码函数之前或之内添加它).
我不想落到最后的解决方案,这是在WordPress formatting.php文件中评论一些行,因为我正在开发一个将被许多人使用的插件.
我有一个类似的问题,我clean_url用过滤器解决了.请在此处查看我的答案中的编辑.
它不是短代码,所以我不能保证它会在你的特定情况下工作.可能值得一试.
由oyatek 编辑 (来自链接的修改后的解决方案):
function so_handle_038($content) {
$content = str_replace(array("&","&"), "&", $content);
return $content;
}
add_filter('the_content', 'so_handle_038', 199, 1);
Run Code Online (Sandbox Code Playgroud)