wp_unregister_font_collection()


WordPressのwp_unregister_font_collection()関数は、登録済みのフォントコレクションを解除するために使用されます。この関数は、特定のフォントコレクションを削除したい場合に役立ちます。

構文

wp_unregister_font_collection( string $collection_id );
  • $collection_id (string) — 解除するフォントコレクションのID。

例1: フォントコレクションの解除

登録済みのフォントコレクションを解除する基本的な例です。

wp_unregister_font_collection( 'my-custom-font-collection' );

例2: 条件付きでフォントコレクションを解除

特定の条件が満たされた場合にのみフォントコレクションを解除します。

if ( some_condition() ) { wp_unregister_font_collection( 'my-custom-font-collection' ); }

例3: 複数のフォントコレクションを解除

複数のフォントコレクションを一度に解除します。

wp_unregister_font_collection( 'collection-1' ); wp_unregister_font_collection( 'collection-2' );

例4: フォントコレクションの存在を確認して解除

フォントコレクションが存在する場合にのみ解除します。

if ( wp_font_collection_exists( 'my-custom-font-collection' ) ) { wp_unregister_font_collection( 'my-custom-font-collection' ); }

例5: テーマ内でのフォントコレクション解除

テーマのfunctions.phpファイル内でフォントコレクションを解除します。

add_action( 'after_setup_theme', function() { wp_unregister_font_collection( 'theme-font-collection' ); } );

例6: プラグイン内でのフォントコレクション解除

プラグイン内でフォントコレクションを解除します。

add_action( 'init', function() { wp_unregister_font_collection( 'plugin-font-collection' ); } );

例7: 特定のユーザーロールに対してフォントコレクションを解除

特定のユーザーロールに対してのみフォントコレクションを解除します。

if ( current_user_can( 'editor' ) ) { wp_unregister_font_collection( 'editor-font-collection' ); }

例8: フォントコレクション解除後のフック

フォントコレクションを解除した後にアクションを実行します。

add_action( 'wp_unregistered_font_collection', function( $collection_id ) { error_log( 'フォントコレクションが解除されました: ' . $collection_id ); } );

注意点

  • フォントコレクションを解除すると、そのコレクションに依存するスタイルが無効になる可能性があります。
  • 解除するフォントコレクションのIDが正しいことを確認してください。

関連機能: