* 親テーマのウィジェットを子テーマで上書きする [#qc10528e]

*** 子テーマのfunctions.php [#l17380db]

 function my_widgets_init() {
     register_widget( 'X_Archives_Widget' );
 	register_sidebar(array() );
 }
 
 function remove_parent_widgets() {
     remove_action( 'widgets_init', 'twentysixteen_widgets_init' );
 }
 
 add_action('after_setup_theme', 'remove_parent_widgets');
 add_action('after_setup_theme', 'my_widgets_init');

- 親テーマのfunctions.phpの中にあるwidgets_initを確認する。
-- 今回はtwentysixteen_widgets_init。
- そのwidgets_initをremove_action()で削除する関数を、子テーマのfunctions.phpに作る。
-- 今回はremove_parent_widgets()。
- その関数呼ぶため、after_setup_themeでadd_action()する。
- さらにafter_setup_themeでadd_action()して、今度は子テーマのwidgets_initを呼ぶ。
-- 今回はmy_widgets_init()呼んでいる。

** 参考 [#re3866e1]

http://wordpress.stackexchange.com/questions/235156/how-to-modify-single-widget-in-child-theme/235163

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS