最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - How to pass the API key to the client from the database?

programmeradmin4浏览0评论
Closed. This question is off-topic. It is not currently accepting answers.

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.

Closed 3 years ago.

Improve this question

I wrote this simple client in javascript that uses mapbox geocoding API. It is not necessary to hide the API key but what is the correct way of giving that js file access to the API key without hardcoding it?

Is it a good solution to embed the API key in the html file in a hidden div and have js read it from that div?

Closed. This question is off-topic. It is not currently accepting answers.

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.

Closed 3 years ago.

Improve this question

I wrote this simple client in javascript that uses mapbox geocoding API. It is not necessary to hide the API key but what is the correct way of giving that js file access to the API key without hardcoding it?

Is it a good solution to embed the API key in the html file in a hidden div and have js read it from that div?

Share Improve this question asked Aug 9, 2021 at 21:21 Dangz1Dangz1 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 2

Assuming you are using wp_enqueue_script to load the .js, then use wp_localize_script to set the value of your key.

Another option is to use wp_add_inline_script instead of wp_localize_script.

发布评论

评论列表(0)

  1. 暂无评论