wp_localize_script in WordPress: Passing PHP Data to JavaScript
Вставка
- Опубліковано 26 вер 2024
- Follow the link below to Check Out the Ultimate Guide on How to add Javascript & jQuery to WordPress
plethorathemes...
Make any server side data (PHP) available to your scripts (JavaScript) using the WordPress wp_localize_script function.
JavaScript Code: gist.github.co...
PHP Code:
gist.github.co...
Codex: wp_localize_script Reference
codex.wordpres... - Навчання та стиль
Good day. Your video is getting the closest to an answer I think I might need. So what f Im not on a child theme but a custom theme entirely?
What if we want to use plain javascript?
Hello Edward. You can use plain JavaScript without any problem. Just replace the jQuery code with a simple JS function.
@@plethorathemes Thanks. Would you be able to share the code for plain Javascript?
@@edwards9845 Sure. You can use the following code:
document.addEventListener("DOMContentLoaded", function(){
alert( php_data.message );
});
Let us know if everything worked out OK for you.
@@plethorathemes Thanks!