如何将jquery添加到wordpress插件

This could be a very easy question to wordpress expert. I am a newbie in wordpress and I am having problem using jquery on it. The jquery library is already included because you can see it firebug

I dont know what I am missing here.

This is my code..

add_action( 'wp_enqueue_scripts', array( $this, 'jsscript' ) );


function jsscript() {   
    ?>
    <script type="text/javascript">
        $(document).ready(function(){
            alert('here!');
        });
    </script>
    <?php
    }

The jsscript is already on the firebug but it doesn't work. I am getting this error message in firebug.

ReferenceError: $ is not defined
$(document).ready(function(){

I read somewhere that it is not a good idea to include another jquery library and it make sense not to load it again.

I hope somebody can help me.

Thanks in advance.

Instead of just randomly outputting your script you should add it in an external file in your plugin directory, and then include that file with jQuery as a dependency

wp_enqueue_script(
      'jsscript', 
      plugin_dir_path( __FILE__ ) . '/jsscript.js', 
      array( 'jquery' )
);

The issue you're having now, is that there's no guarantee that the script is outputted after jQuery, in fact there's now guarantee that the script tag you're outputting between the PHP tags is inserted where it's supposed to go at all.

Put this code your functions.php file

function yourfunction_name() {
global $wp_scripts;
    wp_register_script('jqury_lib', "//code.jquery.com/jquery-1.11.2.min.js", array(), null);
}
add_action( 'wp_enqueue_scripts', 'yourfunction_name' );

To avoid conflict between other js libraries global $ is not present in wordpress instead use jQuery

Read this for more info

for eg:

jQuery(document).ready(function () {
    alert('here!');
});

For theme:

wp_enqueue_script(
        'custom-script',
        get_stylesheet_directory_uri() . '/js/custom_script.js',
        array( 'jquery' )
    );

For plugin:

wp_enqueue_script(
        'newscript',
        plugins_url( '/js/newscript.js' , __FILE__ ),
        array( 'scriptaculous' )
    );