php - wordpress - jQuery doesn't work in plug in, but works everywhere else? -
sorry easy question, (hey, easy rep!) i'm new php of 1 day. have create wordpress plugin/widget out of necessity. have en queued jquery in header:
`<?php wp_enqueue_script("jquery"); ?>`
and created class intended clicked in plugin.
jquery('.court').click(function () { alert(jquery(this).attr('id')); });
simple stuff , works if place code within footer (which has nothing else in jq). not work if it's inside plugin. javascript alert('boom'); work in plugin.
what missing in order use jquery within plugin? don't want put in footer since won't packaged there.
i have create wordpress plugin/widget out of necessity. writing plugin scratch? if so; try adding code below anywhere in plugin's main file:
<?php function mypluginscripts() { wp_enqueue_script( 'jquery-my-plugin', get_site_url() . "/wp-includes/js/jquery/jquery.js", array(), ''); // in function, can add other js files // uncomment line below & change values if need // wp_enqueue_script( 'my-plg-js', 'path/to/my-plg.js', array('jquery'), ''); } add_action('wp_enqueue_scripts', 'mypluginscripts');
Comments
Post a Comment