How to Add Custom Fonts to a WordPress Theme 1

How to Add Custom Fonts to a WordPress Theme

function my_custom_fonts() { 
    wp_enqueue_style( 'my-custom-fonts', get_template_directory_uri() . '/assets/fonts/open-sans/open-sans.css', false );
}
add_action( 'wp_enqueue_scripts', 'my_custom_fonts' );

Here is what the above code is Doing:
1. It’s adding a new action to the wp_enqueue_scripts hook.
2. It’s calling the my_custom_fonts() function when the wp_enqueue_scripts hook is called.
3. It’s registering the my-custom-fonts style with the wp_register_style() function.
4. It’s enqueuing the my-custom-fonts style with the wp_enqueue_style() function.
5. It’s using the get_template_directory_uri() function to get the URL of the current theme’s directory.
6. It’s using the /assets/fonts/open-sans/open-sans.css path to get the URL of the Open Sans font file.

Similar Posts