Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

jquery and wordpress

i am having difficulty making my jquery functions operate within wordpress.

can anyone help out with why these should work normally but not in wordpress???

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It seems like you have to load the script using wp_enque_script. You can find the documentation for this function and for loading scripts in WordPress in general at the codex page for wp_enque_script. Furthermore, I found an article on Using jQuery with WordPress that provides sample code for the loading of the script and then the use of it.

If you look at the Codex documentation, it says:

The jQuery library included with Wordpress loads in "no conflict" mode.

So to be able to use the $() function as usual, you have to do

jQuery(document).ready(function($) {
    // $() will work as an alias for jQuery() inside of this function
});

For an example of what that looks like, look at step 2 of the Themocracy article linked above.

I'm pretty sure you'll be fine with these resources, hope they help.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...