php - 当我在函数中替换它们时 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__title
所以page-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>';
}
...它将应用相同的样式,但这不起作用。当我检查代码时,即使我在代码中更改了类名,它们也没有改变。我怎样才能使这项工作?
解决方案
我弄清楚了问题所在。该函数根本没有运行,因为我是从父主题调用它。我需要在子主题 functions.php 中创建一个新函数并调用它而不是父主题中的函数。
推荐阅读
- java - 使用 url android studio (Java) 设置壁纸
- f# - F# CsvProvider MissingMethodException
- javascript - 在一个 WordPress 主题上调整浏览器窗口的大小以及添加 JS 代码移动菜单关闭按钮后,导航栏不起作用
- scala - 惰性 val 如何解决前向引用扩展 scala 中的值定义
- python - 带有额外空格的 CSV
- sql - Firebase BigQuery,在触发“app_remove”之前获取 event_name
- javascript - 如何使用简单的 html 在 textarea 中保留换行符?
- ios - 无法在 iOS 设备上发送 UDP 广播 - NWConnection
- google-cloud-platform - 使用 Google 自然问题 (NQ) 数据集
- redis - 有什么方法可以关闭空闲的 redis-client 连接?