我认为谷歌地图API加载不正确是一个问题。您需要确保jQuery和Google maps API都已加载。
https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
http://maps.google.com/maps/api/js
它可以是jQuery的任何最新版本,也可以来自任何来源。
假设jQuery函数包含在google maps地址中。jQuery完成加载后,下面的js文件将加载该文件。
function googleaddress_function() {
wp_enqueue_script( \'google-maps-api\', \'http://maps.google.com/maps/api/js\' ); //Add this line
wp_enqueue_script( \'googleaddress\', get_template_directory_uri() . \'-child-theme/google-maps-address.js\', array( \'jquery\' ), null, true); //Add jquery dependency
}
add_action(\'wp_enqueue_scripts\',\'googleaddress_function\');
然后,您可以将jQuery函数设置为无冲突模式(见下文)
jQuery(document).ready(function($) {
$("address").each(function(){
var embed ="<iframe width=\'100%\' height=\'350\' frameborder=\'0\' scrolling=\'no\' marginheight=\'0\' marginwidth=\'0\' src=\'https://maps.google.com/maps?&q="+ encodeURIComponent( $(this).text() ) +"&output=embed\'></iframe>";
$(this).html(embed);
});
});
简而言之,这是一个交换第一个
$
具有
jQuery
然后添加
$
到函数后面的括号。
希望这能解决你的问题,我也附上了一个例子。
http://codepen.io/raptorkraine/pen/JGKBvx