Skip to main content

How to enqueue script and css file in child-theme and main plugin file in worpress?

enqueue script and css file in child-theme or main plugin file in worpress



FOR Child theme


function theme_js() {
wp_enqueue_script( 'theme_js', get_stylesheet_directory_uri() . '/js/custom.js', array( 'jquery' ));
}

add_action('wp_enqueue_scripts', 'theme_js');



FOR main plugin file 


function ecom_scripts(){
wp_enqueue_script("jquery");
wp_enqueue_script( 'foundation-script', plugins_url('/slider/foundation.min.js', __FILE__));
wp_enqueue_script( 'slick-script', plugins_url('/slider/slick.min.js', __FILE__));
// wp_enqueue_style( 'foundation-style', plugins_url('/slider/foundation.css', __FILE__));
wp_enqueue_style( 'slick-style', plugins_url('/slider/slick.css', __FILE__)); 
    wp_enqueue_script( 'ecom-script', plugins_url('/js/custom.js', __FILE__));
wp_localize_script( 'ecom-script', 'myajax', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
wp_enqueue_style( 'ecom-style', plugins_url('/css/stylesheet.css', __FILE__));


}
add_action("wp_enqueue_scripts","ecom_scripts");

Comments

Popular posts from this blog

How to check date format in PHP?

Check date format in PHP function isCorrectDateFromat($date){     if(!empty($date)){         $dateString = $date; // Replace this with your date string         $format = "Y-m-d"; // Replace this with your expected date format         $dateTime = DateTime::createFromFormat($format, $dateString);         if ($dateTime === false) { /*             echo "The date is not in the correct format."; */         } else {             $errors = DateTime::getLastErrors();             if (empty($errors)) { /*                 echo "The date is in the correct format."; */                 return true;             } else { /*                 echo "...