ページ内目次

ウィジットエリアを追加する 実は簡単♡

テーマにウィジェットを追加するには2つのステップ

1. function.php にウィジェットエリアを登録

2. テーマに、ウィジェット表示を設定


1. function.php にウィジェットエリアを登録

if (function_exists('register_sidebar')) {
  register_sidebar(array(
     'name' => 'MyWidget' ,
     'id' => 'mywidget' ,
     'description' => 'ウィジェットの説明',
     'before_widget' => '<div class="widget">',
     'after_widget' => '</div>',
     'before_title' => '<h3>',
     'after_title' => '</h3>'
  ));
}

name:ウィジェット設定画面に表示される名称(日本語可)

id:ウィジェットのID(※ユニークな名前。半角英数字)

before_widget:ウィジェットの前に表示するタグ

after_widget:ウィジェットの後に表示するタグ

before_title:ウィジェットのタイトルの前に表示するタグ

after_title:ウィジェットのタイトルの後に表示するタグ

2. テーマに、ウィジェット表示を設定

これだけ

<?php dynamic_sidebar('ウィジェットのID'); ?>

 

This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

Accept or Deny

↑上へまいりま〜す