My WP Trek

Playing with WordPress

Using .js and .css file with WordPress

WordPress function used to register, enqueue and localize javascript and css files.

add_action( 'init', 'register_script_style' );

function register_script_style() {
    wp_register_style( 'your_style_name', $url_to_your_css_folder . '/your-style.css', array(), $version );
    wp_register_script( 'your_script_name', $url_to_your_js_folder . '/your-script.js', array( 'jquery' ), $version, true );
    wp_enqueue_script( 'your_script_name' );
    wp_enqueue_style( 'your_style_name' );
    //Localize your script
    $params = array(
        'ajaxurl' => admin_url( 'admin-ajax.php' ),
        'ajax_nonce' => wp_create_nonce( 'my_ajax_nonce' ),
    wp_localize_script( 'your_script_name', 'my_ajax', $params );


Using .js and .css file with WordPress

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top