{"id":52860,"date":"2015-08-28T02:29:30","date_gmt":"2015-08-28T06:29:30","guid":{"rendered":"http:\/\/www.templatemonster.com\/help\/?p=52860"},"modified":"2017-08-16T06:42:31","modified_gmt":"2017-08-16T10:42:31","slug":"cherryframework-4-how-to-include-custom-js-file","status":"publish","type":"post","link":"https:\/\/www.templatemonster.com\/help\/cherryframework-4-how-to-include-custom-js-file.html","title":{"rendered":"CherryFramework 4. How to include custom JS file"},"content":{"rendered":"<p>\r\n<p>This tutorial shows how to include custom JS file in CherryFramework 4 templates.<\/p>\r\n<p><a href=\"http:\/\/www.youtube.com\/watch?v=nJiN5fpCyO8?width=1280&amp;height=720\" rel=\"prettyPhoto\">CherryFramework 4. How to include custom JS file<\/a><\/p>\r\n<div class=\"inline-banner\">\r\n<a href=\"https:\/\/www.templatemonster.com\/service-center\/\">\r\n<img src=\"\/help\/files\/banners\/inline\/Banner-3-(835-x100).jpg\" \/>\r\n<\/a>\r\n<\/div>\r\n<p>The best practice to insert custom JS files is to register and enqueue them. Once the file is created and you&#8217;re ready to proceed, perform the following steps:<\/p>\r\n<ol>\r\n<li>\r\n<p>Open your WordPress admin panel and navigate to <strong>Appearance> Editor> theme####> Theme Functions (function.php)<\/strong> file. Add new PHP line right below opening <strong>&lt;?php <\/strong>tag on top:<\/p>\r\n<pre class=\"brush:js\">\/\/include custom JS file\r\nwp_enqueue_script( 'custom-scripts', get_stylesheet_directory_uri().'\/js\/my_custom_script.js', array('jquery'), '1.0' );<\/pre>\r\n<p>Using <strong>&quot;\/\/&quot; <\/strong>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.<\/p>\r\n<p><strong>Note:  <\/strong>provided script contains the reference to the actual JS file included. Make  sure that <strong>&#8216;my_custom_script.js&#8217; <\/strong>title in the code is replaced with your actual JS file name:<\/p>\r\n<p><a href=\"\/help\/wp-content\/uploads\/2015\/08\/CherryFramework-4_How_to_include_custom_JS_file_1.gif\"><img loading=\"lazy\" src=\"\/help\/wp-content\/uploads\/2015\/08\/CherryFramework-4_How_to_include_custom_JS_file_1-300x228.gif\" alt=\"CherryFramework-4_How_to_include_custom_JS_file_1\" width=\"300\" height=\"228\" class=\"aligncenter size-medium wp-image-52861\" srcset=\"https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2015\/08\/CherryFramework-4_How_to_include_custom_JS_file_1-300x228.gif 300w, https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2015\/08\/CherryFramework-4_How_to_include_custom_JS_file_1-150x114.gif 150w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a>\r\n  <\/li>\r\n<li>\r\n<p>The script placed to<strong> functions.php<\/strong> 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 <strong>&#8216;wp-content\/themes\/theme####\/&#8217;<\/strong> directory (where theme##### is your actual child theme).<\/p>\r\n<\/li>\r\n<li>\r\n<p>In case there is no<strong> &#8216;js&#8217; <\/strong>folder by default, you should create it manually.<\/p>\r\n<p class=\"attention\"><strong>Note: <\/strong>make sure<strong> the folder title is &#8216;js&#8217; specifically (case sensitive)<\/strong>.<\/p>\r\n<\/li>\r\n<li>\r\n<p>Now open the new <strong>&#8216;js&#8217; <\/strong>folder and<strong> upload your custom JS file<\/strong> inside.<\/p>\r\n<p class=\"attention\"><strong>Note: <\/strong>double check the title of the actual file and the way it is written in the functions.php. They should to be identical:<\/p>\r\n<p><a href=\"\/help\/wp-content\/uploads\/2015\/08\/CherryFramework-4_How_to_include_custom_JS_file_2.gif\"><img loading=\"lazy\" src=\"\/help\/wp-content\/uploads\/2015\/08\/CherryFramework-4_How_to_include_custom_JS_file_2-300x228.gif\" alt=\"CherryFramework-4_How_to_include_custom_JS_file_2\" width=\"300\" height=\"228\" class=\"aligncenter size-medium wp-image-52862\" srcset=\"https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2015\/08\/CherryFramework-4_How_to_include_custom_JS_file_2-300x228.gif 300w, https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2015\/08\/CherryFramework-4_How_to_include_custom_JS_file_2-150x114.gif 150w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a>\r\n  <\/li>\r\n<\/ol>\r\n<p>Feel free to check the detailed video tutorial below:<\/p>\r\n<p><a href=\"http:\/\/www.youtube.com\/watch?v=nJiN5fpCyO8?width=1280&amp;height=720\" rel=\"prettyPhoto\">CherryFramework 4. How to include custom JS file<\/a><\/p>\r\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>This tutorial  shows you how to include custom JS file in CherryFramework 4.<\/p>\n","protected":false},"author":66,"featured_media":52865,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[2017,728],"tags":[2012,789,918,1086],"_links":{"self":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/posts\/52860"}],"collection":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/users\/66"}],"replies":[{"embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/comments?post=52860"}],"version-history":[{"count":1,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/posts\/52860\/revisions"}],"predecessor-version":[{"id":82718,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/posts\/52860\/revisions\/82718"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/media\/52865"}],"wp:attachment":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/media?parent=52860"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/categories?post=52860"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/tags?post=52860"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}