WordPress - why is my filter hook not working?

38 Views Asked by At

This get_customizer_fonts_options filter currently exists in the parent theme that I'm using. I'm also using a child theme and need to change this list of fonts.

Is it as simple as copying this into my child theme's functions.php file and changing the list of fonts, or do I use add_filter and create my own function with the changes? Thanks for any insight. I'm stumped.

get_customizer_fonts_options filter that lives in the parent theme:

if ( ! function_exists('get_customizer_fonts_options' ) ) {
    // Generates array with options used with typography control so all font lists have the same choises.
    function get_customizer_fonts_options( $context = false, $default = false ) {
        if ( $default ) {
            $default = array( 'inherit' => esc_html__( 'Default font', 'coll_school' ) );
        } else {
            $default = array();
        }
        if ( $context == 'header' ) {
            $fonts =  $default + array(
                    'public_sans'   => 'Public Sans',
                    'amstelvar'     => 'Amstelvar',
                    'commissioner'  => 'Commissioner',
                    
                );
        } else {
            $fonts = $default + array(
                    'public_sans'  => 'Public Sans',
                    'amstelvar'    => 'Amstelvar',
                    'commissioner' => 'Commissioner',
                    
                );
        }

        
        return apply_filters('get_customizer_fonts_options', $fonts, $context );
    }
}

My add_filter code in my child theme functions.php file that is not working:

function hwp_control_font_list($fonts, $context) {
if ( $default ) {
            $default = array( 'inherit' => esc_html__( 'Default font', 'cpschool' ) );
        } else {
            $default = array();
        }
   if ( $context == 'header' ) {
            $fonts =  $default + array(
                    'quicksand'     => 'Quicksand',
                    'raleway'       => 'Raleway',
                    'russolo'       => 'Russolo',
                    'roboto'       => 'Roboto',
                    
                );
        } else {
            $fonts = $default + array(
                    'quicksand'    => 'Quicksand',
                    'raleway'      => 'Raleway',
                    'roboto'       => 'Roboto',
                    
                );
        }
}
add_filter('get_customizer_fonts_options','hwp_control_font_list', 2);
0

There are 0 best solutions below