How to Load Custom Javascript Script in WordPress
来源:互联网 发布:java公路自行车怎么样 编辑:程序博客网 时间:2024/05/13 20:19
While there are a number of articles out there showing you how to properly load jquery in WordPress, none of them seem to show you how to load a custom javascript script in WordPress.
This is how you load custom javascript / jquery script into WordPress in Genesis.
/** Load the scripts at the bottom of the page to increase performance and user experience This is Genesis specific and may vary depending on WordPress theming framework*/add_action('genesis_after_footer', 'load_custom_js');function load_custom_js() {//Only load the scripts on non-admin pagesif (!is_admin()){//Load jquery core from Jquery.com directlywp_enqueue_script('my_jquery','http://code.jquery.com/jquery-1.10.1.min.js',array( 'jquery' ));//Load custom jquery or js script from child theme folder wp_enqueue_script('my_custom_js',get_stylesheet_directory_uri().'/js/customjs.js',array( 'jquery' ));}}
The most important line in the above code snippet is:
wp_enqueue_script(‘my_custom_js’,get_stylesheet_directory_uri().’/js/customjs.js’,array( ‘jquery’ ));
my_custom_js is the script handler. Could call it anything.
get_stylesheet_directory_uri() is an inbuilt WP function that gets the file url of your stylesheet directory, which is especially useful in the Genesis framework as this gets your child theme directory file url.
js/customjs.js is the name of your custom js script and the folder it is stored in (js).
- How to Load Custom Javascript Script in WordPress
- HOW TO Load a Custom Script with Dependencies
- How to do custom statistic in OPNET
- How to create custom price in Magento?
- How to execute shell script in Java?
- How to write a script in Linux
- How to write comment in PowerShell Script
- how to execute sql script in c#
- How to run a script in ubuntu?
- How to launche powershell script in C#
- how to answer Y in gdb script?
- How to answer 'yes' in bash Script
- How to Implement Ajax in WordPress Themes
- How to: load DDS files in OpenGL.
- How to load "CodedUItestmethod" in another "consoleapplication".
- How to OOP in Javascript
- How To Install Custom Component in Delphi (into existing package).
- How to define a custom separator in TLex
- commons DBCP 配置参数简要说明
- JavaScript(Jquery)中让网页停顿几秒或按时间循环执行(定时器,已解决,可直接执行!)
- MVC4重命名项目后可能发生的错误
- 维生素E
- 三種批量存儲數據的方法
- How to Load Custom Javascript Script in WordPress
- 一些国内大型互联网公司的前端框架
- AUPE学习第八章------进程控制
- MFC - m_pMainWnd
- 三维图形数据格式 STL的 读取
- iGson
- 指针函数与函数指针
- 维生素E2
- Java中printf的使用举例