• Hi,

    I’m trying to add a Jquery javascript file to my plugin however after reading the documentation and trying various examples online I’m still not having any success. Could someone please point me in the right direction. Below is my php file:

    class WordPressWidget extends WP_Widget {
              function WordPressWidget() {
                        $widget_ops = array(
                        'classname' => 'WordPressWidget',
                        'description' => 'new wordpress widget/plugin'
              ); 
    
              $this->WP_Widget(
                        'WordPressWidget',
                        'WordPress Widget,
                        $widget_ops
              );
    }
    
              function widget($args, $instance) { // widget sidebar output
                        extract($args, EXTR_SKIP);
                        echo $before_widget; // pre-widget code from theme
    					print ('<h2 class="blocktitle">WordPress Widget</h2> ');
    					print ('<input type="text" id="txtText" />   <input id="btnButton" type="button" disabled="disabled" value="submit form" />');
                        echo $after_widget; // post-widget code from theme
              }
    
    		  	  function load_scripts()  {
    			// Register the script like this for a plugin:
    			wp_register_script( 'custom-script', FRM_URL . ( '/js/my-utils.js' ), array( 'jquery' ) );
    			// or
    			// Register the script like this for a theme:
    			//wp_register_script( 'custom-script', '/js/my-utils.js', array( 'jquery' )  );  
    
    			// For either a plugin or a theme, you can then enqueue the script:
    			wp_enqueue_script( 'custom-script' );
    		  }
    
    }
    
    add_action( 'wp_enqueue_scripts', 'load_scripts' );
    add_action( 'widgets_init', create_function('','return register_widget("WordPressWidget");')
    
    );

    [Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

The topic ‘Add a javascript file to a plugin HELP!’ is closed to new replies.