How can you enqueue scripts and styles in WordPress?

How can you enqueue scripts and styles in WordPress?

To enqueue scripts and styles in WordPress, follow these minimal steps:

Step 1: Use wp_enqueue_script and wp_enqueue_style

In your theme’s functions.php file, use the following functions to enqueue scripts and styles.

Step 2: Enqueue Styles

Example

<?php
function my_theme_enqueue_styles() {
    wp_enqueue_style('my-custom-style', get_stylesheet_directory_uri() . '/css/custom-style.css');
}
add_action('wp_enqueue_scripts', 'my_theme_enqueue_styles');
?>

Step 3: Enqueue Scripts

Example

<?php
function my_theme_enqueue_scripts() {
    wp_enqueue_script('my-custom-script', get_template_directory_uri() . '/js/custom-script.js', array('jquery'), null, true);
}
add_action('wp_enqueue_scripts', 'my_theme_enqueue_scripts');
?>

Related Questions & Topics

Powered and designed by igetvapeaustore.com | © 2024 codestap.com.