0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

WordPressのウィジェットを有効化する方法

Last updated at Posted at 2020-12-15

WordPressウィジェットは必ず使うと思うので

テーマを開発する時は有効にしておくと良いです。

##WordPressウィジェットを有効化する方法

function.php
/* ---------------------------------------
ウィジェットの有効化
--------------------------------------- */
function my_theme_widgets() {
    register_sidebar(array(
         'name' => 'サイド',
         'id' => 'side_widget' ,
         'before_widget' => '<div class="side-widget">',
         'after_widget' => '</div>',
         'before_title' => '<h2 class="widget-side-title">',
         'after_title' => '</h2>'
    ));
    register_sidebar(array(
         'name' => 'フッター',
         'id' => 'footer_widget' ,
         'before_widget' => '<div class="footer-widget">',
         'after_widget' => '</div>',
         'before_title' => '<h2 class="widget-footer-title">',
         'after_title' => '</h2>'
    ));
    }
    add_action( 'widgets_init', 'my_theme_widgets' );

サイド用とフッター用を設置してみました。

あとは使いたいページのphpファイルに下記のようにかく!!

php
//サイド
<?php dynamic_sidebar('side_widget'); ?>
php
//フッター
<?php dynamic_sidebar('footer_widget'); ?>

##さいご
以上!!
ではまた!!!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?