如何使用 child 主题使以下标题在 h4 标签而不是 h2 中输出标题?

How do I make the following heading output the title in an h4 tag instead of h2 using a child theme?

所以我希望边栏标题位于 h4 标签中 this is how the site structure is currently looking

这是从中提取标题的代码:

genesis_markup(
[
    'open'    => '<aside %s>' . genesis_sidebar_title( 'sidebar' ),
    'context' =>  'sidebar-primary',
]

您可以使用 genesis_sidebar_title_output 过滤器来修改 genesis_sidebar_title 函数的输出。

使用下面的代码片段将所有侧边栏标题的标签切换为 h4:

<?php
add_filter('genesis_sidebar_title_output', 'so_modify_sidebar_title', 10, 2);
function so_modify_sidebar_title($heading, $id) {
    global $wp_registered_sidebars;
    
    $name = $id;

    if ( array_key_exists( $id, $wp_registered_sidebars ) ) {
      $name = $wp_registered_sidebars[ $id ]['name'];
      $heading = '<h4 class="genesis-sidebar-title screen-reader-text">' . $name . '</h4>';
    }

    return $heading;
}