1. Including CSS (Styles)
Use wp_enqueue_style to include CSS files.
Example:
function mytheme_enqueue_styles() {
// Include the main theme stylesheet
wp_enqueue_style('mytheme-main-style', get_stylesheet_uri());
// Include an additional CSS file
wp_enqueue_style(
'mytheme-custom-style', // Unique identifier
get_template_directory_uri() . '/assets/css/custom.css', // File path
array(), // Dependencies (e.g., other styles)
'1.0.0' // File version
);
}
add_action('wp_enqueue_scripts', 'mytheme_enqueue_styles');
2. Including JavaScript
Use wp_enqueue_script to include JavaScript files.
Example:
function mytheme_enqueue_scripts() {
// Include a custom JS file
wp_enqueue_script(
'mytheme-custom-script', // Unique identifier
get_template_directory_uri() . '/assets/js/custom.js', // File path
array('jquery'), // Dependencies (e.g., jQuery)
'1.0.0', // File version
true // Load in the footer (true for before `