如何修改子主题中的单个控件?

时间:2016-08-06 作者:jrcollins

我正在尝试修改子主题中的小部件标题H2H1. 我从父主题的functions.php 文件到子主题的function.php 按照中的说明归档this thread. 这是我在子主题中放置的代码functions.php 文件:

remove_action(\'widgets_init\', \'codilight_lite_widgets_init\');

//Register your own hook.
add_action(\'widgets_init\', \'my_widgets_init\');

function my_widgets_init() {
register_sidebar( array(
    \'name\'          => esc_html__( \'Default Sidebar\', \'codilight-lite\' ),
    \'id\'            => \'sidebar-1\',
    \'description\'   => \'\',
    \'before_widget\' => \'<aside id="%1$s" class="widget %2$s">\',
    \'after_widget\'  => \'</aside>\',
    \'before_title\'  => \'<h2 class="widget-title"><span>\',
    \'after_title\'   => \'</span></h2>\',
) );

// Homepage Template
register_sidebar( array(
    \'name\'          => esc_html__( \'Home 1\', \'codilight-lite\' ),
    \'id\'            => \'home-1\',
    \'description\'   => \'\',
    \'before_widget\' => \'<aside id="%1$s" class="home-widget %2$s">\',
    \'after_widget\'  => \'</aside>\',
    \'before_title\'  => \'<h2 class="widget-title"><span>\',
    \'after_title\'   => \'</span></h2>\',
) );
register_sidebar( array(
    \'name\'          => esc_html__( \'Home 2\', \'codilight-lite\' ),
    \'id\'            => \'home-2\',
    \'description\'   => \'\',
    \'before_widget\' => \'<aside id="%1$s" class="home-widget %2$s">\',
    \'after_widget\'  => \'</aside>\',
    \'before_title\'  => \'<h2 class="widget-title"><span>\',
    \'after_title\'   => \'</span></h2>\',
) );
register_sidebar( array(
    \'name\'          => esc_html__( \'Home 3\', \'codilight-lite\' ),
    \'id\'            => \'home-3\',
    \'description\'   => \'\',
    \'before_widget\' => \'<aside id="%1$s" class="home-widget %2$s">\',
    \'after_widget\'  => \'</aside>\',
    \'before_title\'  => \'<h2 class="widget-title"><span>\',
    \'after_title\'   => \'</span></h2>\',
) );
register_sidebar( array(
    \'name\'          => esc_html__( \'Home 4\', \'codilight-lite\' ),
    \'id\'            => \'home-4\',
    \'description\'   => \'\',
    \'before_widget\' => \'<aside id="%1$s" class="home-widget %2$s">\',
    \'after_widget\'  => \'</aside>\',
    \'before_title\'  => \'<h1 class="widget-title"><span>\',
    \'after_title\'   => \'</span></h1>\',
) );

}
我试图修改的小部件是列表中的最后一个,即Home 4 小部件。这段代码没有产生任何错误,只是不起作用。

1 个回复
最合适的回答,由SO网友:jrcollins 整理而成

看来我找到答案了here.这是我在我的孩子主题中使用的代码的工作版本functions.php 文件

function my_widgets_init() {
register_sidebar( array(
    \'name\'          => esc_html__( \'Default Sidebar\', \'codilight-lite\' ),
    \'id\'            => \'sidebar-1\',
    \'description\'   => \'\',
    \'before_widget\' => \'<aside id="%1$s" class="widget %2$s">\',
    \'after_widget\'  => \'</aside>\',
    \'before_title\'  => \'<h2 class="widget-title"><span>\',
    \'after_title\'   => \'</span></h2>\',
) );

// Homepage Template
register_sidebar( array(
    \'name\'          => esc_html__( \'Home 1\', \'codilight-lite\' ),
    \'id\'            => \'home-1\',
    \'description\'   => \'\',
    \'before_widget\' => \'<aside id="%1$s" class="home-widget %2$s">\',
    \'after_widget\'  => \'</aside>\',
    \'before_title\'  => \'<h2 class="widget-title"><span>\',
    \'after_title\'   => \'</span></h2>\',
) );
register_sidebar( array(
    \'name\'          => esc_html__( \'Home 2\', \'codilight-lite\' ),
    \'id\'            => \'home-2\',
    \'description\'   => \'\',
    \'before_widget\' => \'<aside id="%1$s" class="home-widget %2$s">\',
    \'after_widget\'  => \'</aside>\',
    \'before_title\'  => \'<h2 class="widget-title"><span>\',
    \'after_title\'   => \'</span></h2>\',
) );
register_sidebar( array(
    \'name\'          => esc_html__( \'Home 3\', \'codilight-lite\' ),
    \'id\'            => \'home-3\',
    \'description\'   => \'\',
    \'before_widget\' => \'<aside id="%1$s" class="home-widget %2$s">\',
    \'after_widget\'  => \'</aside>\',
    \'before_title\'  => \'<h2 class="widget-title"><span>\',
    \'after_title\'   => \'</span></h2>\',
) );
register_sidebar( array(
    \'name\'          => esc_html__( \'Home 4\', \'codilight-lite\' ),
    \'id\'            => \'home-4\',
    \'description\'   => \'\',
    \'before_widget\' => \'<aside id="%1$s" class="home-widget %2$s">\',
    \'after_widget\'  => \'</aside>\',
    \'before_title\'  => \'<h1 class="widget-title"><span>\',
    \'after_title\'   => \'</span></h1>\',
) );

}

add_action(\'after_setup_theme\',\'remove_parent_widgets\');

function remove_parent_widgets() {
remove_action( \'widgets_init\', \'codilight_lite_widgets_init\' );
}
add_action( \'after_setup_theme\', \'my_widgets_init\' );

相关推荐

EDIT-Comments.php COMMENT_ROW_ACTIONS AJAX问题

在编辑注释上。php页面,我正在连接到comment\\u row\\u actions过滤器,以便在末尾添加另一个链接。我正在复制“Approve”链接,添加另一个查询键和值,并修改锚文本。我想根据新查询键的值添加一些注释元。批准的链接:/wp-admin/comment.php?c=9999&action=approvecomment&_wpnonce=8526c66已批准的元链接/wp-admin/comment.php?c=9999&action=approvecommen