首页 > 解决方案 > 当我在函数中替换它们时 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>';
}

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

标签: phphtmlwordpress

解决方案


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


推荐阅读