テーマをウィジェットに対応させる
Word Pressのテーマによってはウィジェットに対応していない場合があります。
その場合はfunctions.php、ウィジェットを使用するテンプレート(sidebar.phpなど)への記述が必要となります。
functions.php
<?php
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
));
}
?>
ウィジェットを表示されたい場所に下記のコードを記述します。
sidebar.phpなど
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
<?php endif; ?>
なお、出力されるHTML、class名を変更したい場合は、
上記のfunctions.phpを修正していきます。
例えば出力されるウィジェットのタイトルを、
「class名は無しで、h3タグにしたい」
といった場合は以下のように記述します。
functions.php
<?php
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h3>',
'after_title' => '</h3>',
));
}
?>
タグ: functions.php, sidebar.php, ウィジェット
記事公開日:
最終更新日:








[…] 参照URL:https://wpmemo.netkatuyou.com/theme/561/ […]