1

$Twenty Thirteen テーマの子テーマを使用して wordpress (v. 3.6) サイトを構築しています。私のテーマの header.php には

<body <?php body_class(); ?> onResize="resizeHandler();">

これは、テーマ myChildTheme.js の .js ファイルです。

var myStuff;
function resizeHandler() {
    myStuff = jQuery(".stuff");
    console.log("resized, and here's stuff: "+ myStuff);
}

「jQuery」の代わりに $ を使用するために、Web で見つけた解決策を試しました。新しい myChildTheme.js:

jQuery(document).ready(function($) {
    var myStuff;
    function resizeHandler() {
        myStuff = $(".stuff");
        console.log("resized, and here's stuff: "+ myStuff);
    }
});

しかし、resizeHandler が定義されていないというコンソール参照エラーが表示されます。

テーマのスクリプトとスタイルを、正しいと思われる方法でエンキューして登録しました。

functions.php:

function myChildTheme_scripts_styles() {
    wp_enqueue_style( 'myChildTheme-fonts', myChildTheme_fonts_url(), array(), null );
}
add_action( 'wp_enqueue_scripts', 'myChildTheme_scripts_styles' );

function myChildTheme_scripts() {
    wp_enqueue_script('myChildTheme_functions', get_stylesheet_directory_uri().'/js/myChildTheme.js', array('jquery'), '', true);
    wp_enqueue_script('isotope_source', get_stylesheet_directory_uri().'/js/jquery.isotope.min.js', array('jquery'), '', true);
}
add_action( 'wp_enqueue_scripts', 'myChildTheme_scripts' );

$ を機能させる方法に関するヒントはありますか? ありがとう。

4

1 に答える 1