2

I'm trying to enqueue javascript and css in WordPress. I have written the following code but it is not working and no style or css is being added to my theme.

function add_theme_scripts() {

  wp_enqueue_style( 'cssdatepicker', get_template_directory_uri() . '/css/persian-datepicker.css', array(), '1.1', 'all');

  wp_enqueue_script( 'jsdate', get_template_directory_uri() . '/js/persian-date.js', array ( 'jquery' ), '1.1', true);
   wp_enqueue_script( 'jsdatepicker', get_template_directory_uri() . '/js/persian-datepicker.js', array ( 'jquery' ), '1.1', true);

}
add_action( 'wp_enqueue_scripts', 'add_theme_scripts' );
mujuonly
  • 11,370
  • 5
  • 45
  • 75
Somy J
  • 173
  • 1
  • 3
  • 22

1 Answers1

2

I think it will be added but it showing you cache version CSS and js which is blank maybe

function add_theme_scripts() {

  wp_enqueue_style( 'cssdatepicker', get_template_directory_uri(). '/css/persian-datepicker.css', array(), null, 'all');

  wp_enqueue_script( 'jsdate', get_template_directory_uri() . '/js/persian-date.js', array ( 'jquery' ), null, true);
   wp_enqueue_script( 'jsdatepicker', get_template_directory_uri() . '/js/persian-datepicker.js', array ( 'jquery' ), null, true);

}
add_action( 'wp_enqueue_scripts', 'add_theme_scripts' );

use this code to run updated js and CSS file ( non-cache )

  • OR

it is already added to your site but the path is wrong so it will throw an error in console.

you can see in the console using the F12 key

please check and let me know what is your status.

  • OR

wp_enqueue_script( string $handle, string $src = '', array $deps = array(), string|bool|null $ver = false, bool $in_footer = false )

if your $handle has already existed with other style or script so it will not be added to your theme or plugin so be careful about this and add the unique name of $handle

Note :- Add Unique name of $handle or add your own prefix before name of $handle like custom_jquery this is our custom jquery $handle name

Refrence site :- WP Codex wp_enqueue_script

dev_ramiz_1707
  • 671
  • 4
  • 20