Leo
Leo

Reputation: 158

Wordpress and plugins

How can i add a javascript function to the php?

Im trying this and nothing happens

    <?php
/*
Plugin Name: PluginTest
Description: Just a test.
Version: 1.0.0
*/

add_action('wp_enqueue_scripts','c_leo_init');

function c_leo_init() {
  $src = plugins_url('js/lb_carrosel.js', __FILE__);

  wp_register_script( 'lb_carrosel', $src );
  wp_enqueue_script( 'lb_carrosel' );

}

My js function

function lb_carrosel(){
  alert('hi');
}

Upvotes: 0

Views: 31

Answers (1)

Han
Han

Reputation: 21

In your JS file, you may need to call the function lb_carrosel():

function lb_carrosel(){
  alert('hi');
}

lb_carrosel();

Upvotes: 1

Related Questions