我正在尝试使用以下语法加载Google Maps API:
add_action('admin_enqueue_scripts', 'load_google_maps');
...
function load_google_maps()
{
// The actual API key is configured in an options page
$key = get_option('google_maps_api_key');
$gmaps_url = 'http://maps.googleapis.com/maps/api/js?key=' . $key . '&sensor=false';
wp_enqueue_script('google-maps', $gmaps_url, NULL, NULL);
}
WordPress正在将"&"转义为"&"。这实际上使得Google服务器拒绝请求。当我在浏览器地址栏直接输入带有"&sensor=false"的内容时,它可以正常加载。
我在WordPress跟踪系统中看到了一个类似的错误http://core.trac.wordpress.org/ticket/9243,但被视为无效,并且管理员回复请求者表明"&"方法是可行的。从Google的角度来看,这绝对不可行。
当然,我可以让函数将HTML作为脚本标记输出,但如果可能的话,我更愿意使用wp_enqueue_script系统。
有人知道解决方案吗?
干杯,
raff
&
替换&
完美解决了问题。 - codewithfeeling