Closed. This question is off-topic. It is not currently accepting answers.admin管理员组文章数量:1130349
Closed 6 years ago.
- Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
- Questions that are too localized (such as syntax errors, code with restricted access, hacked sites, hosting or support issues) are not in scope. See how do I ask a good question?
I'm setting up a google map on my site and I'm trying to set the enqueue my scripts up but am getting an error:
I have placed this code in my functions.php (actual api key not used here):
function rt_load_acf_map()
{
// Register my scripts for my theme:
wp_register_script( 'map-script', get_stylesheet_directory_uri() . '/js/acf-map.js', array( 'jquery' ) );
wp_register_script( 'googlemap', '' , '', '', false );
wp_register_script( 'slider-script', get_stylesheet_directory_uri() . '/js/slider.js', array( 'jquery' ) );
// For either a plugin or a theme, you can then enqueue the script:
wp_enqueue_script( 'map-script' );
wp_enqueue_script( 'googlemap' );
if(is_front_page()){
wp_enqueue_script( 'slider-script' );
}
}
add_action( 'wp_enqueue_scripts', 'rt_load_acf_map' );
the map loads on the front end but with an overlay error:
This page can't load Google Maps correctly.
In my console I see this error:
Google Maps JavaScript API warning: NoApiKeys
and when I look at the page source i see that & and then the version were added:
<script type='text/javascript' src=';#038;ver=4.9.8'></script>
EDITS
The api key is correct and working. That's not the issue.
Secondly, when I remove the wp_register_script and its wp_enqueue and just use this line:
wp_enqueue_script( 'google-maps-api', '//maps.googleapis/maps/api/js?key=123123123123', array(), '', true );
Everything works fine.
I can't figure out why it's not working as wone line and with the http in front of google maps url.
Closed. This question is off-topic. It is not currently accepting answers.
Closed 6 years ago.
- Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
- Questions that are too localized (such as syntax errors, code with restricted access, hacked sites, hosting or support issues) are not in scope. See how do I ask a good question?
I'm setting up a google map on my site and I'm trying to set the enqueue my scripts up but am getting an error:
I have placed this code in my functions.php (actual api key not used here):
function rt_load_acf_map()
{
// Register my scripts for my theme:
wp_register_script( 'map-script', get_stylesheet_directory_uri() . '/js/acf-map.js', array( 'jquery' ) );
wp_register_script( 'googlemap', 'https://maps.googleapis/maps/api/js?123123123123' , '', '', false );
wp_register_script( 'slider-script', get_stylesheet_directory_uri() . '/js/slider.js', array( 'jquery' ) );
// For either a plugin or a theme, you can then enqueue the script:
wp_enqueue_script( 'map-script' );
wp_enqueue_script( 'googlemap' );
if(is_front_page()){
wp_enqueue_script( 'slider-script' );
}
}
add_action( 'wp_enqueue_scripts', 'rt_load_acf_map' );
the map loads on the front end but with an overlay error:
This page can't load Google Maps correctly.
In my console I see this error:
Google Maps JavaScript API warning: NoApiKeys https://developers.google/maps/documentation/javascript/error-messages#no-api-keys
and when I look at the page source i see that & and then the version were added:
<script type='text/javascript' src='https://maps.googleapis/maps/api/js?123123123123&ver=4.9.8'></script>
EDITS
The api key is correct and working. That's not the issue.
Secondly, when I remove the wp_register_script and its wp_enqueue and just use this line:
wp_enqueue_script( 'google-maps-api', '//maps.googleapis/maps/api/js?key=123123123123', array(), '', true );
Everything works fine.
I can't figure out why it's not working as wone line and with the http in front of google maps url.
Share Improve this question edited Nov 27, 2018 at 16:22 rudtek asked Nov 26, 2018 at 19:26 rudtekrudtek 6,4035 gold badges30 silver badges52 bronze badges 2- There's a link right there in the console that explains what the problem is. What's not clear? – Jacob Peattie Commented Nov 27, 2018 at 16:15
- @JacobPeattie Thanks for your help. What's not clear is why i'm getting that message. I understand what that message means, but the api code is being sent Additional information added above as well. Thanks again. – rudtek Commented Nov 27, 2018 at 16:24
2 Answers
Reset to default 4When you call google, the key variable name is missing.
wp_register_script( 'googlemap', 'https://maps.googleapis/maps/api/js?123123123123' , '', '', false );
Should be :
wp_register_script( 'googlemap', '//maps.googleapis/maps/api/js?key=123123123123123123123123' , '', '', false );
Setting the $ver parameter to false (or, probably, '', as you've done), will append the current WordPress version to the <script> tag. To have no version number appended, use null instead:
wp_register_script(
'googlemap',
'https://maps.googleapis/maps/api/js?123123123123',
array(),
null,
false
);
(Also, the $deps parameter should be an empty array rather than an empty string, which is also addressed in the code above.)
However: I don't think this is the actual problem you're having. The error message in your question suggests that you don't have an API key for Google Maps, which is an issue you'll have to sort out with Google.
Reference
wp_register_script() docs
Closed 6 years ago.
- Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
- Questions that are too localized (such as syntax errors, code with restricted access, hacked sites, hosting or support issues) are not in scope. See how do I ask a good question?
I'm setting up a google map on my site and I'm trying to set the enqueue my scripts up but am getting an error:
I have placed this code in my functions.php (actual api key not used here):
function rt_load_acf_map()
{
// Register my scripts for my theme:
wp_register_script( 'map-script', get_stylesheet_directory_uri() . '/js/acf-map.js', array( 'jquery' ) );
wp_register_script( 'googlemap', '' , '', '', false );
wp_register_script( 'slider-script', get_stylesheet_directory_uri() . '/js/slider.js', array( 'jquery' ) );
// For either a plugin or a theme, you can then enqueue the script:
wp_enqueue_script( 'map-script' );
wp_enqueue_script( 'googlemap' );
if(is_front_page()){
wp_enqueue_script( 'slider-script' );
}
}
add_action( 'wp_enqueue_scripts', 'rt_load_acf_map' );
the map loads on the front end but with an overlay error:
This page can't load Google Maps correctly.
In my console I see this error:
Google Maps JavaScript API warning: NoApiKeys
and when I look at the page source i see that & and then the version were added:
<script type='text/javascript' src=';#038;ver=4.9.8'></script>
EDITS
The api key is correct and working. That's not the issue.
Secondly, when I remove the wp_register_script and its wp_enqueue and just use this line:
wp_enqueue_script( 'google-maps-api', '//maps.googleapis/maps/api/js?key=123123123123', array(), '', true );
Everything works fine.
I can't figure out why it's not working as wone line and with the http in front of google maps url.
Closed. This question is off-topic. It is not currently accepting answers.
Closed 6 years ago.
- Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
- Questions that are too localized (such as syntax errors, code with restricted access, hacked sites, hosting or support issues) are not in scope. See how do I ask a good question?
I'm setting up a google map on my site and I'm trying to set the enqueue my scripts up but am getting an error:
I have placed this code in my functions.php (actual api key not used here):
function rt_load_acf_map()
{
// Register my scripts for my theme:
wp_register_script( 'map-script', get_stylesheet_directory_uri() . '/js/acf-map.js', array( 'jquery' ) );
wp_register_script( 'googlemap', 'https://maps.googleapis/maps/api/js?123123123123' , '', '', false );
wp_register_script( 'slider-script', get_stylesheet_directory_uri() . '/js/slider.js', array( 'jquery' ) );
// For either a plugin or a theme, you can then enqueue the script:
wp_enqueue_script( 'map-script' );
wp_enqueue_script( 'googlemap' );
if(is_front_page()){
wp_enqueue_script( 'slider-script' );
}
}
add_action( 'wp_enqueue_scripts', 'rt_load_acf_map' );
the map loads on the front end but with an overlay error:
This page can't load Google Maps correctly.
In my console I see this error:
Google Maps JavaScript API warning: NoApiKeys https://developers.google/maps/documentation/javascript/error-messages#no-api-keys
and when I look at the page source i see that & and then the version were added:
<script type='text/javascript' src='https://maps.googleapis/maps/api/js?123123123123&ver=4.9.8'></script>
EDITS
The api key is correct and working. That's not the issue.
Secondly, when I remove the wp_register_script and its wp_enqueue and just use this line:
wp_enqueue_script( 'google-maps-api', '//maps.googleapis/maps/api/js?key=123123123123', array(), '', true );
Everything works fine.
I can't figure out why it's not working as wone line and with the http in front of google maps url.
Share Improve this question edited Nov 27, 2018 at 16:22 rudtek asked Nov 26, 2018 at 19:26 rudtekrudtek 6,4035 gold badges30 silver badges52 bronze badges 2- There's a link right there in the console that explains what the problem is. What's not clear? – Jacob Peattie Commented Nov 27, 2018 at 16:15
- @JacobPeattie Thanks for your help. What's not clear is why i'm getting that message. I understand what that message means, but the api code is being sent Additional information added above as well. Thanks again. – rudtek Commented Nov 27, 2018 at 16:24
2 Answers
Reset to default 4When you call google, the key variable name is missing.
wp_register_script( 'googlemap', 'https://maps.googleapis/maps/api/js?123123123123' , '', '', false );
Should be :
wp_register_script( 'googlemap', '//maps.googleapis/maps/api/js?key=123123123123123123123123' , '', '', false );
Setting the $ver parameter to false (or, probably, '', as you've done), will append the current WordPress version to the <script> tag. To have no version number appended, use null instead:
wp_register_script(
'googlemap',
'https://maps.googleapis/maps/api/js?123123123123',
array(),
null,
false
);
(Also, the $deps parameter should be an empty array rather than an empty string, which is also addressed in the code above.)
However: I don't think this is the actual problem you're having. The error message in your question suggests that you don't have an API key for Google Maps, which is an issue you'll have to sort out with Google.
Reference
wp_register_script() docs
本文标签: Enqueuing script is adding extra text for google maps
版权声明:本文标题:Enqueuing script is adding extra text for google maps 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749148025a2323333.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论