---
title: "オリジナルのウィジット作成方法"
description: "WordPressオリジナルのウィジットエリアを作成して表示する為の設定方法。テーマカスタマイズ、ウィジットエリアのカスタマイズ、オリジナルウィジットの設定方法についての覚書メモ。"
url: "https://www.sensitivity.jp/wordpress/%e3%82%aa%e3%83%aa%e3%82%b8%e3%83%8a%e3%83%ab%e3%81%ae%e3%82%a6%e3%82%a3%e3%82%b8%e3%83%83%e3%83%88%e4%bd%9c%e6%88%90%e6%96%b9%e6%b3%95/"
canonical: "https://www.sensitivity.jp/wordpress/%e3%82%aa%e3%83%aa%e3%82%b8%e3%83%8a%e3%83%ab%e3%81%ae%e3%82%a6%e3%82%a3%e3%82%b8%e3%83%83%e3%83%88%e4%bd%9c%e6%88%90%e6%96%b9%e6%b3%95/"
date: "2020-05-31"
modified: "2020-06-29"
categories: ["WordPress"]
---

# オリジナルのウィジット作成方法

覚書メモ
 Wordpressのサイドバーエリアにオリジナルのウィジットを作成する方法

## register_sidebar

### functions.phpの設定

```

register_sidebar( array(
 'id' => 'mysidebar', //任意のid
 'name' => 'マイサイドバー', //ウィジットに表示される名前
 'description' => '内容についての説明', //サイドバーに表示される内容についての説明内容
 'before_widget' => '<aside>', //ウィジットの前にタグを出力する：スタイルなどを使用するならクラスなども設定
 'after_widget' => '</aside>', //ウィジットの後にタグを出力する
 'before_title' => '<h2 class="widget-title">', //ウィジットにタイトルを出力する場合等
 'after_title' => '</h2>'
));
```

### ウィジットを表示

登録したウィジットの内容をテンプレートファイルに記述する

```

<?=dynamic_sidebar('mysidebar')?> //functions.phpで登録したウィジットのidを呼び出す。
```

  補足

register_sidebarのパラメーター

| キー | 値 | 初期置 | 内容 |
| --- | --- | --- | --- |
| name | 文字列 | sprintf( __( 'Sidebar %d' ), $i ) 'Sidebar' を翻訳した文字列と ID の数字（$i） 例：サイドバー1 | ウィジットエリアの名前 |
| id | 文字列 | "sidebar-$i"; （$i は登録したサイドバーの連番。最初は1） | ウィジットエリアのID |
| description | 文字列 | '' | ウィジットの管理画面に表示されるウィジットエリアの説明 |
| class | 文字列 | '' | 管理画面のウィジットエリアに割り当てられるCSSクラス |
| before_widget | 文字列 | '<li id="%1$s" class="widget %2$s">' sprintf で変数を置換。 （%1$s はウィジェットの名前+番号、%2$s は widget_ウィジェットの名前） | 登録したウィジットの直前にhtmlを出力 |
| after_widget | 文字列 | '</li>\n' | 登録したウィジットの直後にhtmlを出力 |
| before_title | 文字列 | '<h2 class="widgettitle">' | 登録ウィジットのタイトルの直前にhtmlを出力 |
| after_title | 文字列 | '</h2>\n' | 登録ウィジットのタイトルの直後にhtmlを出力 |

[ウィジットの使い方](https://ja.wordpress.org/support/article/wordpress-widgets/)
  [テーマのウィジェット対応:WordPress Codex 日本語版](https://wpdocs.osdn.jp/%E3%83%86%E3%83%BC%E3%83%9E%E3%81%AE%E3%82%A6%E3%82%A3%E3%82%B8%E3%82%A7%E3%83%83%E3%83%88%E5%AF%BE%E5%BF%9C)

