This tutorial shows how to include custom JS file in CherryFramework 4 templates.
The best practice to insert custom JS files is to register and enqueue them. Once the file is created and you’re ready to proceed, perform the following steps:
Open your WordPress admin panel and navigate to Appearance> Editor> theme####> Theme Functions (function.php) file. Add new PHP line right below opening <?php tag on top:
//include custom JS file wp_enqueue_script( 'custom-scripts', get_stylesheet_directory_uri().'/js/my_custom_script.js', array('jquery'), '1.0' );
Using "//" commenting tag is optional, you can add it to place some description text for the php code (if needed). Update the file once finished editing.
Note: provided script contains the reference to the actual JS file included. Make sure that ‘my_custom_script.js’ title in the code is replaced with your actual JS file name:
The script placed to functions.php specifies the directory for the included JS file. So, you should upload it to the server. Open server files using either FTP client or hosting File Manager. Navigate to the ‘wp-content/themes/theme####/’ directory (where theme##### is your actual child theme).
In case there is no ‘js’ folder by default, you should create it manually.
Note: make sure the folder title is ‘js’ specifically (case sensitive).
Now open the new ‘js’ folder and upload your custom JS file inside.
Note: double check the title of the actual file and the way it is written in the functions.php. They should to be identical:
Feel free to check the detailed video tutorial below: