' P '

whatever I will forget

wordpress に bootstrap を 導入

1.ローカル環境にwordpressを導入する。

MAMPを使ってローカル環境にWordPressをインストールする方法

上記リンクをそのまんまやる。

 

2.新しくthemeとして作ったフォルダにbootstrapを突っ込む。

Getting · Bootstrap

上記リンクからダウンロード。左のコンパイルされたやつ。

 

3.index.php と style.cssを作成する

 

4.index.phpに書く内容は

Getting · Bootstrap ←のexampleのソースコードをそのまま貼り付ける。

 

5.index.phpスタイルシートを読み込んでいるところを下記に置き換え

<link href="<?php bloginfo('stylesheet_url');?>" rel="stylesheet" media="screen">

 

6.index.phpの</head>直前に以下を挿入

<?php wp_enqueue_script("jquery"); ?>
<?php wp_head(); ?>

 

7.index.phpの</body>直前に以下を挿入

<?php wp_footer(); ?>

 

8.style.cssに以下を挿入

@import url('bootstrap/css/bootstrap.min.css');
@import url('bootstrap/css/bootstrap-responsive.min.css');
body {
padding-top: 60px;
padding-bottom: 40px;
}

 

9.functions.phpに以下を挿入

<?php

function wpbootstrap_scripts_with_jquery()
{
// Register the script like this for a theme:
wp_register_script( 'custom-script', get_template_directory_uri() . '/bootstrap/js/bootstrap.js', array( 'jquery' ) );
// For either a plugin or a theme, you can then enqueue the script:
wp_enqueue_script( 'custom-script' );
}
add_action( 'wp_enqueue_scripts', 'wpbootstrap_scripts_with_jquery' );

?>

 

これでどうぞ。

うまくいかない場合は下記が挙げられる

cssが適応されてない

jqueryが動いていない

javascriptが動いていない

wordpress用のphpタグが動いていない

どれかです。

 

chromeならmore tool -> javascript console でエラーの理由がわかるかも。

not found系ならコードをもっかい見直す。

・二重でjqueryjavascriptをロードしていないか。