WordPressでjQuery

WordPressでjQueryを使った事を書こうとかと思ったんだけど、
そもそも自分のWordPressではjQueryが動かなかった。

他のprototype.jsなどと一緒に使われて問題が起きないように、
$ を使えないようにしているらしいが、そういうレベルでなく
jQueryワードが定義されてないと出た。

まぁ、原因はよくわからないが、とにかくjQueryが動くようにした。

header.phpで共通のJavaScriptなどを読んでるらしいので、
Linuxのfind コマンドでWordPressを展開している辺りで、header.phpの場所を検索。

#find /var/www -name header.php

テーマごとにheader.php見つかるので、
自分が使用しているテーマのheader.phpを開き、

<?php wp_head(); ?>

 

の直前に前の記事で書いたようにgoogleのload関数を導入

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1");
google.load("jqueryui", "1");
</script>

これで使用可能となった。

テスト文字を消す
テスト
今のところ他で影響はでていない模様。

 

参考:http://javatechnology.net/wordpress/wordpress-jquery-google/

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>