S
S
Sergey Gorchakov2015-09-29 16:53:41
PHP
Sergey Gorchakov, 2015-09-29 16:53:41

How to set JS variables from Wordpress admin?

For php, I created a special settings page in Wordpress, in which the site administrator could specify parameter variables and these variables would be displayed in a special code in the right place on the site. For example, there is a calculator in php. So that the admin does not get into the code, he simply goes to the admin panel, indicates the values ​​\u200b\u200bof the calculator variables, changes prices and it’s convenient for everyone, everyone is fine.
Now I have a JS calculator. Is it possible to display variables in the admin panel in a similar way so that the admin does not have to go into the script itself for changes?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Korolev, 2015-09-30
@mistype

Some damn thing. Why use a localizer , gentlemen? It is needed, I will not be afraid of these words, for localization, for translation. And for the things TC wants to do, there is such a thing as JSON.
So (in the sense - they use json to pass variables to JS) Google does it, Stackoverflow does it (see the source code), so do all normal people. And so do you.

S
Sergiu Mitu, 2015-09-29
@EaGames

Custom fields + wp_localize_script Usage
example via ACF

wp_localize_script('script_name', 'variable_name', get_field('field_name', 'options'));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question