The WordPress API provides the functions wp_enqueue_style()
and wp_enqueue_script()
for including stylesheets and JavaScript.
These functions should be used instead of hardcoding style or script tags within HTML.
// Runs wpse_enqueue_styles() on the wp_enqueue_scripts() hook.
// (Yes, we're enqueuing a stylesheet here, but the proper hook is wp_enqueue_scripts.
add_action( 'wp_enqueue_scripts', 'wpse_enqueue_styles' );
function wpse_enqueue_styles() {
wp_enqueue_style(
// Handle
'example-font',
// Source (URL) for stylesheet.
// Here, the stylesheet resides at /theme-name/css/MyFontsWebfontsKit.css
get_stylesheet_directory_uri() . '/css/MyFontsWebfontsKit.css',
// Dependencies for stylesheet. None in this case.
array()
);
}
Place the code above in your theme’s functions.php
file. Note that the “wpse_” prefix should be changed to match whatever is used by your theme.