I
I
Ivan2015-10-06 17:50:35
WordPress
Ivan, 2015-10-06 17:50:35

How to connect styles and scripts to a WordPress plugin?

Good afternoon. I recently started making one plugin, and there was a problem that I can’t connect the styles and scripts that are in its directory to this plugin.
Tried something like this:

add_action('init', 'register_script');
function register_script() {
    wp_register_script( 'custom_jquery', plugins_url('/js/custom-jquery.js', __FILE__), array('jquery'), '2.5.1' );

    wp_register_style( 'new_style', plugins_url('/css/new-style.css', __FILE__), false, '1.0.0', 'all');
}

And many more like it. But there is no reaction. Suspicions fell on the fact that I may not be putting this code there. I put it in the main file name_plugin.php which lies at the root of the plugin.
Tell me how and where to insert it? Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
WP Panda, 2015-10-06
@wppanda5

add_action('init', 'register_script');
function register_script() {
    wp_register_script( 'custom_jquery', plugins_url('/js/custom-jquery.js', __FILE__), array('jquery'), '2.5.1' );
    wp_register_style( 'new_style', plugins_url('/css/new-style.css', __FILE__), false, '1.0.0', 'all');
    wp_enqueue_script('custom_jquery');
    wp_enqueue_style('new_style' );
}

H
HoHsi, 2015-10-06
@HoHsi

Your JQ depends on itself.
array('jquery')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question