How do i call a javascript function from wordpress?

Can I call a JavaScript function in Wordpress like this?


Where should I put my JavaScript? at footer.php? or what would be the proper way to achieve something like this?

I put my script in footer.php, then I called the function like as I mentioned but no use?

asked May 28, 2015 at 6:06

1

Yes you can use title="callGetDomain[];" and for the function definition, use a separate js file and include that file using wp_enqueue_script[], which is the proper way to call js files in Wordpress. Check this

answered May 28, 2015 at 6:10

Vidya LVidya L

2,2514 gold badges26 silver badges41 bronze badges

Contents

  • 1 JavaScript in Template Files
  • 2 JavaScript in Posts
  • 3 Creating a Multiple Script File
  • 4 Troubleshooting JavaScript
  • 5 Resources

JavaScript will work within WordPress. If used within the template files, most JavaScript will work fine. Here are a few tips to make your JavaScript work in WordPress.

JavaScript in Template Files

To use JavaScript repeatedly within your site, you can either set the call for the JavaScript, or the script itself, in the head of your header.php template file, between the meta tags and the style sheet link, no differently than you would if you were using JavaScript in any HTML page. To "load" the JavaScript file into your site, in the head, add something like this:

Be sure that you define the type correctly, as your site will not validate without it.

In the spot where you wish to use the JavaScript, set the call for the JavaScript. For example, you are using a JavaScript that sets a link for users to "email this page" to a friend and you want it to be under the post title. It might look like this:

Chủ Đề