0

私は子テーマを持っており、以下をフィルタリングしようとしています:

// add the function to the init hook
add_action( 'init', 'options_typography_get_google_fonts' );

// add a font to the $google_fonts variable
function options_typography_get_google_fonts() {

    // Google Font Defaults
    global $google_faces;
    $google_faces = array(

        'Great Vibes, cursive' => '*Great Vibes'    
        );

    return $google_faces;

}

Google フォントを追加できるようにこれをフィルタリングする最良の方法は何ですか?

4

1 に答える 1

0

あなたの質問は少し漠然としているので、いくつかの選択肢があります:

(1) 親テーマがoptions_typography_get_google_fonts関数が存在するかどうかを確認する場合 ( を使用function_exists)、子テーマで再宣言することで関数をオーバーライドできます。

(2) 親テーマにない場合は、子テーマのアクションを削除できるはずです。

remove_action( 'init', 'options_typography_get_google_fonts' );

削除したばかりの関数に基づいて、独自の (類似しているが拡張された) 関数を作成します。

(3) 子テーマを構築していて、ユーザーがフォントのリストをフィルタリングできるようにしたい場合は、フィルタリング可能な配列を返す必要があります。

return apply_filters( 'my_options_typography_get_google_fonts_filter', $google_faces );

于 2013-04-22T12:04:10.283 に答える