开发者

Wordpress Admin and JavaScript

Im writing a plugin and have allot of custom Javascript. (shudder). I would like to only enque these javascript and other ass开发者_如何学JAVAets when needed. They are loaded on my plugin pages and also will be neede on the post / page / custom post type edit screens. Is there a simple and best practice method for doing so?

cheers


You could use a load-(page) action function to conditionally add your enqueue calls on specific pages.

add_action('load-post.php', 'my_load_post_php_action');
function my_load_post_php_action() {
    wp_enqueue_script('my_script', plugins_url('my_script.js', __FILE__));
}


Use enqueue script, that will avoid all JS conflicts.

A better explanation on this link:

http://codex.wordpress.org/Function_Reference/wp_enqueue_script

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜