Question Detail

My index.php is unable to call css and js files even after using function.php with wp_enqueue_script and wp_enqueue_style codes.

And can u pls tell me how can I attach any image or file with my question in QnA?


Thread Reply

Naini

- 1 years ago

I am stuck pls help..

 

Bili Greed

- 1 years ago

you can see get_stylesheet_directory_uri() return correct https URI, but then on the site all scripts added via https.

Bili Greed

- 1 years ago

 I think in your theme some other function is overriding the output. Search for other wp_enqueue_scripts functions

wp_enqueue_style and wp_enqueue_script accepts many parameters and it's very important to use them in correct order otherwise these functions will fail.

Here are complete set of parameters for each function.

wp_enqueue_style( $handle, $src, $deps, $ver, $media );
wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer );

In your wp_enqueue_style you define $handle$src correctly but $deps to true which is not correct. Same goes for wp_enqueue_script.

So here is your fixed function.

function load_css_js() {
    wp_enqueue_style( 'gdgt-base', get_template_directory_uri() . '/css/gdgt-base.css', false, NULL, 'all' );
    wp_enqueue_style( 'gdgt-icon', get_template_directory_uri() . '/icons/css/gdgt.css', false, NULL, 'all' );

    wp_register_script( 'gdgt-base', get_template_directory_uri() . '/js/gdgt-base.js', array( 'jquery' ), NULL, false );
    wp_enqueue_script( 'gdgt-base' );
}

add_action( 'wp_enqueue_scripts', 'load_css_js' );

For more information, read documentation for each function on codex.

Hemant Sharma

- 1 years ago

it may help You
https://developer.wordpress.org/reference/functions/wp_enqueue_script/

Hemant Sharma

- 1 years ago

it may help You
https://developer.wordpress.org/reference/functions/wp_enqueue_script/

Anonymous

- 1 years ago

VCS Rocks

 - 2 days ago

it may help You
https://developer.wordpress.org/reference/functions/wp_enqueue_script/

That is the correct way to make it working if it is not.

 

Else please check your CSS path.