目次
今回はWordPressのサイドバーウェジットの設定について、
簡単に書いて行きます。
functions.phpに記述
functions.phpに下記のようなコードを追加します。
必要に応じて書き換えてください。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'widgets_init', 'footerSidebar01_init' ); | |
function footerSidebar01_init() { | |
register_sidebar( array( | |
'name' => __('フッター用サイドバー01'), | |
'id' => 'footersidebar01', | |
'description' => __('フッター用サイドバー01です'), | |
'before_widget' => '<aside id="%1$s" class="footer-side-bar widget %2$s">', | |
'after_widget' => '</aside>', | |
'before_title' => '<div class="">', | |
'after_title' => '</h3>', | |
) ); | |
} |
すると、
WordPress管理画面の「外観」→「ウィジェット」に
サイドバーが作られます。

↑画像のような感じで追加されます。
表示されない場合
たいていの場合小さなミスが原因です。
例えば・・・
・スペルが違う
・末尾のカンマが抜けている
・シングルクォーテーションで囲んでいない
・id=> の所に大文字を使っている
等がよくあります。
サイドバーにアイテム設置

画像のようにアイテムを設置していきます。
表示
表示方法
出したいページのphpファイルに直接、
dynamic_sidebar( 'idに設定した文字' );
で出力します。
簡単にサイドバーを作れるので、WordPressは便利ですね('ω')ノ