2017-01-16 6 views
0

bootstrap.min.jsをネイティブワードプレスjqueryに依存させることができますが、Jquery 1.11.1はソースコードには表示されず、フォントAwesomeも機能しません正しくwp_enqueue_script - 追加のJqueryがソースコードに表示されない

私はstackoverflowの中の他の質問からいくつかのコードを試してみたが、私はまだ、私は以下のコードにいくつかのコメントを入れて、私の質問

を解決することはできません。

更新されたコード

function enqueue_jquery() { 
    // deregister jquery ok 
    wp_deregister_script('jquery'); // unregister the WP-provided jQuery version 

    // tag is not added in code 
wp_enqueue_script(
    'jquery', 
    get_template_directory_uri() . '/js/jquery.js', 
    array(), // don't make jquery dependent on jquery...! 
    '1.11.1', 
    true 
); 

} 
add_action('wp_enqueue_scripts', 'enqueue_jquery'); 

function enqueue_styles_scripts() { 

    //its OK 
    wp_enqueue_style(
     'style-theme', 
     get_stylesheet_uri(), 
     array('bootstrap-css') 
    ); 

    //its OK 
    wp_enqueue_style(
     'bootstrap-css', 
     get_template_directory_uri() . '/css/bootstrap.min.css' 
    ); 

    //its OK 
    wp_enqueue_style(
     'stylish-portfolio', 
     get_template_directory_uri() . '/css/othercss.css' 
    ); 

//I changed the directory of the files to css and fonts folders and it worked correctly 
    wp_enqueue_style(
     'font-awesome', 
     get_stylesheet_directory_uri() . '/css/font-awesome.css' 

    ); 


    //Appears in header but is working correctly 
    wp_enqueue_script(
     'bootstrap-js', 
     get_template_directory_uri() . '/js/bootstrap.min.js',null 
    ); 


} 
add_action('wp_enqueue_scripts', 'enqueue_styles_scripts'); 


//Its Ok  
function wpse_ie_conditional_scripts() { ?> 
    <!--[if lt IE 9]> 
     <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> 
     <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script> 
    <![endif]--> 
    <?php 
} 
add_action('wp_head', 'wpse_ie_conditional_scripts'); 

?> 

答えて

0

が、私は返信用

//Without using function 
    wp_deregister_script('jquery'); 
    wp_register_script('jquery', get_template_directory_uri() . '/js/jquery.js', false, '1.11.1'); 
    wp_enqueue_script('jquery'); 

     function enqueue_styles_scripts() { 

      //its OK 
      wp_enqueue_style(
       'style-theme', 
       get_stylesheet_uri(), 
       array('bootstrap-css') 
      ); 

      //its OK 
      wp_enqueue_style(
       'bootstrap-css', 
       get_template_directory_uri() . '/css/bootstrap.min.css' 
      ); 

      //its OK 
      wp_enqueue_style(
       'stylish-portfolio', 
       get_template_directory_uri() . '/css/othercss.css' 
      ); 

     //its OK 
      wp_enqueue_style(
       'font-awesome', 
       get_stylesheet_directory_uri() . '/css/font-awesome.css' 

      ); 


      //its OK 
      wp_enqueue_script(
       'bootstrap-js', 
       get_template_directory_uri() . '/js/bootstrap.min.js',null 
      ); 


     } 
     add_action('wp_enqueue_scripts', 'enqueue_styles_scripts'); 


     //Its Ok  
     function wpse_ie_conditional_scripts() { ?> 
      <!--[if lt IE 9]> 
       <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> 
       <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script> 
      <![endif]--> 
      <?php 
     } 
     add_action('wp_head', 'wpse_ie_conditional_scripts'); 

     ?> 
+0

これは、作品を言っていますか?あなたはまだjQueryの登録を解除しています - WPフックの外で... bootstrap.min.jsのjquery要件を削除したことに気付きました。 - 確かにwinceのブートストラップは動作しません。* jqueryが必要です... 'wp_enqueue_script( 'bootstrap- js '、get_template_directory_uri()。' /js/bootstrap.min.js '、array(' jquery ')); '? – MacPrawn

+0

はい私の作品、ソースコード ' 'と' Bootstrap.min.js'は完全に動作しています – Gislef

1

したがって、「jquery」はWPによって既に登録され、キューに入れられているという問題があります。私が過去に行ったことは、まずWP提供のjqueryの登録を解除してから、自分のバージョンをエンキューします。 警告:これは完全にWPのインストールのためにjQueryをアップグレードするので、これを完全にテストしてください!

wp_deregister_script('jquery'); // unregister the WP-provided jQuery version 
wp_enqueue_script(
    'jquery', 
    get_template_directory_uri() . '/js/jquery.js', 
    array(), // don't make jquery dependent on jquery...! 
    '1.11.1', 
    true 
); 

また、あなたはノー競合モードでのjQueryのバージョンをロードできますが、それは本当に良いアイデアではありません...

は、この情報がお役に立てば幸い!

+0

感謝をネイティブWordPressのjQueryの登録を解除し、私のテーマのjQueryを登録する機能を使用せずに解決することができた、コードはネイティブのWordPressのjQueryを登録解除が、それはまだですjqueryの登録されていません私のプロジェクトフォルダに – Gislef

+1

本当に - 本当ですか?私は自分の答えを編集し、依存関係として 'array()'を 'null'に変更しましたが、違いはありません...したがって、スクリプトタグはあなたのページのソースに全く追加されません。それとも、ロードされていませんか? (エラー404) – MacPrawn

+0

コード内にjqueryが追加されていません。コンソールに次のエラーが表示されます。 'Uncaught Error:ブートストラップのJavaScriptにjQueryが必要です。 at bootstrap.min.js:6 VM48:402'と' Uncaught ReferenceError: $は定義されていません VM48:402 ' – Gislef

関連する問題