JaroslavM JaroslavM -3 years ago 106
PHP Question

How to link my own .css and .js to wordpress?

I´m trying add my own css a js code which should have influence on element in visual composer created by me. I don not want write my css to style.css of theme. I would rather add css and js with some code in


According to this I try to proceed: developer.wordpress.org

That's what I'm trying to add (in

function theme_styles()
wp_enqueue_style( 'reference-style', get_stylesheet_directory_uri() . '/own-vc-elements/references/reference-style.css' );
wp_enqueue_script( 'reference-script', get_template_directory_uri() . '/own-vc-elements/references/reference-script.js', array('jquery'));
add_action('wp_enqueue_scripts', 'theme_styles');

But it still does not doing anything. What is wrong?

EDIT: Without change. So this should itself add css and js into wordpress system isn't it? If there isn't any mistake.

Browser errors next step

Answer Source

If your script depends on jquery use wp_enqueue_script() third argument as below.

wp_enqueue_script( 'reference-script', get_template_directory_uri() . '/own-vc-elements/references/reference-script.js', array('jquery'));

If is not works again check your script path and check your browser console for 404 error.

In wp_enqueue_style() function parameter replace get_stylesheets_directory_uri() with get_stylesheet_directory_uri() - there is an extra s character -. Also note that you can use get_template_directory_uri() instead of get_stylesheet_directory_uri().


Above code solves the assets load problem.

Another problem in cases like this case is file permissions. Set read permission to files and its parents directory solves the problem.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download