【问题标题】:Cannot redeclare functions.php in child theme (wordpress)无法在子主题(wordpress)中重新声明functions.php
【发布时间】:2021-06-25 07:55:26
【问题描述】:

我在孩子的 functions.php 中遇到错误。 这里有什么问题?

致命错误:无法在 .../functions.php 中重新声明 wpst_get_filter_title()(之前在 .../functions.php:20 中声明)在线 ...

父母的functions.php:

function wpst_get_filter_title() {
    $title  = '';
    $filter = '';
    if ( isset( $_GET['filter'] ) ) {
        $filter = $_GET['filter'];
    } else {
        $filter = xbox_get_field_value( 'wpst-options', 'show-videos-homepage' );
    }
    switch ( $filter ) {
        case 'latest':
            $title = esc_html__( 'Latest videos', 'wpst' );
            break;
        case 'most-viewed':
            $title = esc_html__( 'Most viewed videos', 'wpst' );
            break;
        case 'longest':
            $title = esc_html__( 'Longest videos', 'wpst' );
            break;
        case 'popular':
            $title = esc_html__( 'Popular videos', 'wpst' );
            break;
        case 'random':
            $title = esc_html__( 'Random videos', 'wpst' );
            break;
        default:
            $title = esc_html__( 'Latest videos', 'wpst' );
            break;
    }
    return $title;
}

儿童的functions.php:

    if ( ! function_exists( 'wpst_get_filter_title' ) ) :
function wpst_get_filter_title() {
    $title  = '';
    $filter = '';
    .
    .
    .

    return $title;
}

endif;

【问题讨论】:

    标签: wordpress function fatal-error redeclare


    【解决方案1】:

    你应该在子主题function.php文件中使用不同的函数名,因为当你激活子主题时,它也会调用父主题文件,所以你不能使用函数名两次,所以你应该把这个wpst_get_filter_title()函数名改成其他子主题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-04
      • 1970-01-01
      • 2018-03-24
      • 1970-01-01
      • 2012-11-30
      • 2017-01-16
      • 2023-04-06
      • 1970-01-01
      相关资源
      最近更新 更多