Cannot redeclare functions.php in child theme (wordpress)

1.5k views Asked by At

I'm getting error in child's functions.php. What is wrong here?

Fatal error: Cannot redeclare wpst_get_filter_title() (previously declared in .../functions.php:20) in .../functions.php on line ...

Parent's 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;
}

Child's functions.php:

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

    return $title;
}

endif;
1

There are 1 answers

0
wpdevloper_j On

You should use different function name in child theme function.php file because when you activate child theme, it also call parent theme files so you can not use function name twice so you should change this wpst_get_filter_title() function name to other in child theme.