### [How to Add Custom PHP or JavaScript for WPForms](https://wpforms.com/developers/how-to-add-custom-php-or-javascript-for-wpforms/)

**Published:** October 9, 2019
**Author:** Umair Majeed

**Excerpt:** This tutorial will walk you through several different ways on how to add custom JavaScript and custom PHP snippets to your site. 

**Content:**

Would you like to add custom JavaScript or PHP snippets to your site? This tutorial will give you multiple options on how to add these snippets to your site with step-by-step instructions for each optional way you choose to add your snippet. Adding custom code snippets to your site with PHP or JavaScript can extend the functionality of your site for your specific needs. Whether that be to extend your WordPress theme functionality or extend any plugin functionality.

With this helpful guide, you’ll be able easily choose which way you would like to add the snippets to your site. Once you’ve selected your method of implementation, you can start exploring the developer documentation to pick and chose which snippets you’d like to start adding to your site!

To have a look at the host of snippets available, [please explore our developer documentation](https://wpforms.com/developers/ "WPForms Developer Documentation").

Please see our video tutorial for a more hands-on view of how to achieve adding custom PHP or Javascript to your site.

## Implementation Options

There are a number of approaches available for adding PHP or Javascript to customize your specific needs, not just for WPForms but for any custom code you wish to add.

#### Using WPCode plugin (recommended)

Using the **WPCode** plugin is super fast and easy to add snippets to your site.

Just one of the many reasons we strongly recommend using this plugin for adding custom snippets to your site is that it has a built-in check before saving your snippet. If a semi-colon is missed or an extra bracket is added, the snippet won’t save. This prevents any issues you may experience such as JavaScript error or even PHP Fatal errors from being able to happen on your site due to an incorrect copied and pasted snippet. And yes, even with the free version, you’ll receive this extra audit before your snippet would be made active.

**Note:** To find out more about this plugin, [please check out the site for further information including dedicated documentation](https://wpcode.com/).

Once the plugin is installed, navigate to the **Code Snippets** menu from the left-hand side menu on your WordPress dashboard and select **+ Add Snippet**.

Next, simply click the **Add Your Custom Code (New Snippet)**, then click the blue **Use Snippet** button to create a new snippet.

![from the WPCode menu, click + Add Snippet](https://wpforms.com/wp-content/uploads/2019/10/wpcode-add-new-snippet.png)When your new snippet screen appears, give the snippet a name that will make sense to you so you and your site admins will understand it’s purpose. From the **Code Type** dropdown, select **PHP**.

**Note:** All of the WPForms snippets found throughout our developer documentation would be added as a PHP snippet, even the snippets that use JavaScript, with the exception of specific CSS snippets. This is to make sure if there isn’t a WPForms form on the page, the snippet wouldn’t load the script. This helps reduce the need for loading scripts that do not apply to all pages.

For the purpose of this tutorial, we’re going to be adding the following snippet.

In the **Code Preview** section, add your snippet just under the **<?php**. Here is an example to use for the purpose of this documentation.

```

/**
 * Trigger submit from checkbox click
 *
 * @link https://wpforms.com/developers/how-to-automatically-submit-a-form-with-a-field-choice/
 */
function wpf_dev_automatic_submit_form() {
    ?>

**Categories:** Getting Started

**Tags:** JS, PHP

---

