在函数中替换 CSS 类时它们没有改变?



我正在尝试使主页上显示的网站标题和描述与所有其他页面上的页面标题和描述具有相同的样式,但我遇到了一些问题。以下是显示网站标题和说明的原始函数:

/**
* Displays Site Title and Site Description.
*/
function integer_site_title() {
$class = 'site-branding__copy';
if ( 0 == get_theme_mod( 'header_text', 1 ) ) {
$class .= ' screen-reader-text';
}
printf( '<div class="%s">', esc_attr( $class ) );
if ( is_front_page() && is_home() && get_bloginfo( 'name' ) ) {
printf( '<h1 class="site-title"><a href="%s" rel="home">%s</a></h1>',
esc_url( home_url( '/' ) ),
esc_html( get_bloginfo( 'name' ) )
);
} elseif ( get_bloginfo( 'name' ) ) {
printf( '<p class="site-title"><a href="%s" rel="home">%s</a></p>',
esc_url( home_url( '/' ) ),
esc_html( get_bloginfo( 'name' ) )
);
}
if ( get_bloginfo( 'description' ) ) {
printf( '<p class="site-description">%s</p>', esc_html( get_bloginfo( 'description' ) ) );
}
echo '</div>';
}

其他页面上的页面标题和描述具有类名,page-header__titlepage-header__description.所以,我想如果我只是将网站标题/描述的代码更改为:

function integer_site_title() {
$class = 'site-branding__copy';
if ( 0 == get_theme_mod( 'header_text', 1 ) ) {
$class .= ' screen-reader-text';
}
printf( '<div class="%s">', esc_attr( $class ) );
if ( is_front_page() && is_home() && get_bloginfo( 'name' ) ) {
printf( '<h1 class="page-header__title"><a href="%s" rel="home">%s</a></h1>',
esc_url( home_url( '/' ) ),
esc_html( get_bloginfo( 'name' ) )
);
} elseif ( get_bloginfo( 'name' ) ) {
printf( '<p class="page-header__title"><a href="%s" rel="home">%s</a></p>',
esc_url( home_url( '/' ) ),
esc_html( get_bloginfo( 'name' ) )
);
}
if ( get_bloginfo( 'description' ) ) {
printf( '<p class="page-header__description">%s</p>', esc_html( get_bloginfo( 'description' ) ) );
}
echo '</div>';
}

。它将应用相同的样式,但这不起作用。当我检查代码时,即使我在代码中更改了类名,类名也没有更改。我怎样才能做到这一点?

我想出了问题所在。该函数根本没有运行,因为我是从父主题调用它的。我需要在子主题函数中创建一个新函数.php并调用该函数而不是父主题中的函数。

最新更新