admin管理员组文章数量:1287160
I am using the headers and footers plugin to call a small script I made by pasting the script directly into the user interface of the plugin. However, I would like to upload a JS file and call that instead.
Where should I upload the file? My guess would be the child theme.
I am using the headers and footers plugin to call a small script I made by pasting the script directly into the user interface of the plugin. However, I would like to upload a JS file and call that instead.
Where should I upload the file? My guess would be the child theme.
Share Improve this question asked Apr 23, 2019 at 14:53 mso4491mso4491 11 silver badge1 bronze badge 2- Possible duplicate of Proper Javascript Implementation – MikeNGarrett Commented Apr 23, 2019 at 15:09
- Uploading JS to the media library isn't supported, you're going to have to upload the file to the server itself and modify the PHP code to load it – Tom J Nowell ♦ Commented Apr 23, 2019 at 15:31
1 Answer
Reset to default 2Yes. You will want to enqueue your scripts using wp_enqueue_scripts and then upload them into your child theme. I normally create a /js/
directory to keep things organized.
Here is a sample of how to enqueue a file inside of a themes JS subfolder.
function wpse_enqueue_scripts() {
wp_enqueue_script(
'js-functions',
get_stylesheet_directory_uri() . '/js/functions.js', array('jquery'), filemtime(get_stylesheet_directory() . '/js/functions.js')
);
}
add_action('wp_enqueue_scripts', 'wpse_enqueue_scripts', 999);
本文标签: Where to upload JavaScript file in WordPress
版权声明:本文标题:Where to upload JavaScript file in WordPress 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741306697a2371409.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论