0

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

<?php
/*
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) {
    e.preventDefault();
    jQuery(this).remove();
});

1 Answer 1

0

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' )
14
  • Nope, no effect!
    – Faiz Ahmed
    Commented May 13, 2014 at 19:24
  • is your file being loaded?
    – Milo
    Commented May 13, 2014 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
    Commented May 13, 2014 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
    Commented May 13, 2014 at 19:31
  • So, how would I know?
    – Faiz Ahmed
    Commented May 13, 2014 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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