Skip to main content

How to link css,jquery and ajax with all files via one wordpress function?

link css,jquery and ajax with all files via one wordpress function

copy this code in wordpress function.php file or main plugin file?



function ecom_scripts(){

wp_register_script( 'ecom-script', plugins_url('/js/custom.js', __FILE__), array( 'jquery' ), '', true );
    wp_localize_script( 'ecom-script', 'myajax', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
    wp_enqueue_script( 'ecom-script' );
wp_register_style( 'ecom-style', plugins_url('/css/stylesheet.css', __FILE__), true );
    wp_enqueue_style( 'ecom-style' );
}
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 "...