I am testing jQuery in my wordpress plugin. Two files 1. main_plugin.php 2. js_plugin.js (Both in the same directory HelloWorld).

Plugin Name: jQuery Test Plugin
Plugin URI: http://www.rabwahnetwork.net
Description: This plugin is a test
Author: Rana Faiz Ahmed
Author URI: http://www.rabwahnetwork.net

function load_my_script()
    wp_enqueue_script( 'script-name', WP_PLUGIN_URL . 'HelloWorld/js_plugin.js', array("jquery"), false, true );

add_action( 'wp_enqueue_scripts', 'load_my_script' );

JS file:

jQuery('.entry-header').click(function(e) {

WP_PLUGIN_URL doesn't have a trailing slash, so your script tag is likely trying to load a file from the wrong location.

That said, don't use WP_PLUGIN_URL, use plugins_url() instead.

plugins_url( '/HelloWorld/js_plugin.js' )
  • Nope, no effect! – Faiz Ahmed May 13 '14 at 19:24
  • is your file being loaded? – Milo May 13 '14 at 19:26
  • Yeah I'm editing it from the wordpress backend. Absolutely it is being loading else I wouldn't be editing it. – Faiz Ahmed May 13 '14 at 19:30
  • whether or not you can edit a file on the back end has nothing to do with whether or not it's successfully loading on the front end, your assumption is incorrect. – Milo May 13 '14 at 19:31
  • So, how would I know? – Faiz Ahmed May 13 '14 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.