• I created my own plugin and i attached the css file and its working fine and i attached jquery and it is not working. In jquery file i am just giving the alert message only.

    This is my code:

    add_action(‘wp_enqueue_scripts’, ‘add_to_head’);
    function add_to_head()
    {

    //Adding plugin script to head
    wp_deregister_script( ‘jquery’ );
    wp_register_script(‘jquery’, ‘https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js’);
    wp_enqueue_script(‘jquery’);
    wp_register_script(‘myscript’, plugins_url(‘css/script.js’, __FILE__), array(‘jquery’), ‘1.0’, true );
    wp_enqueue_script(‘myscript’);

    //Adding plugin stylesheet to head
    $src = plugins_url(‘css/style.css’, __FILE__);
    wp_register_style(‘style’, $src);
    wp_enqueue_style(‘style’);

    }

    Jquery Code:

    $j=jQuery.noConflict();

    // Use jQuery via $j(…)
    $j(document).ready(function($){
    alert(‘test’);
    });

  • The topic ‘How to add js file to plugin’ is closed to new replies.