I have a script that requires jQuery, and I don’t know how to add it into a single wordress page.
I looked for many solution, but they are too hard for me to understand.
<script>
$(document).ready(function(e) {
$('#checkboxtest').change(function(){
if( $('#checkboxtest').prop('checked') )
{checkboxstatus = "YES";}
else
{checkboxstatus = "NO";}
$.ajax({
type: "POST",
url: "checkboxtestbackend.php",
data: {checkboxstatus: checkboxstatus},
})
});
});
</script>
4
Answers
There are many ways to add javascript to your WordPress.
The easiest way is to use plugins like this one css javascript toolbox to add your scripts where you need on your WordPress.
Another way is to update your WordPress template and insert your code where it needed. This link provide you a full example of how achieved this: add-javascript-to-wordpress
First of all – you should rewrite your jQuery wrapper for code to work within WP pages:
Now you can add this code to a WordPress page in two ways:
Using a plugin for custom code snippets (like this one)
Or if your page is using a custom-coded template, you can directly paste the
tag with your code, where you need it.
Try this:
Use code like below:
Another example: