-2

So I'm trying to put some javascript into my functions.php and run it from there but everytime I do that I get an error on my page when site is reloaded...

"Parse error: syntax error, unexpected 'wp_enqueue_script' (T_STRING) Local Sites\custom-site\app\public\wp-content\themes\theme\functions.php on line 35"

Here is the code, and yes I did put wp_footer in my footer.php file to run it...

function addjs() {

  wp_register_script('jquery', get_template_directory_uri() . '/plugin-frameworks/jquery-3.2.1.min.js', array() , 1, 1, 1)
  wp_enqueue_script('jquery');

  wp_register_script('bootstrap', get_template_directory_uri() . '/plugin-frameworks/bootstrap.min.js', array() , 1, 1, 1)
  wp_enqueue_script('bootstrap');

  wp_register_script('swiper', get_template_directory_uri() . '/plugin-frameworks/swiper.js', array() , 1, 1, 1)
  wp_enqueue_script('swiper');

  wp_register_script('scripts', get_template_directory_uri() . '/common/scripts.js', array() , 1, 1, 1)
  wp_enqueue_script('scripts');

  wp_register_script('custom', get_template_directory_uri() . '/custom.js', array() , 1, 1, 1)
  wp_enqueue_script('custom');

}

add_action('wp_enqueue_script', 'addjs', 999);

I really don't know what I'm doing wrong here... Thanks in advance :)

COBNETCKNN
  • 21
  • 1
  • 5
  • 1
    All of your `wp_register_script(...)` calls are missing the semicolon (`;`) at the end, hence why you're getting that error message. Fix that and you're good to go. – cabrerahector Nov 25 '19 at 00:57
  • @cabrerahector I knew it was something obvious... much obliged man <3 – COBNETCKNN Nov 25 '19 at 01:11

1 Answers1

0

I edit your script. Hope help you:

function addjs() {

    wp_register_script('jquery', get_template_directory_uri() . '/plugin-frameworks/jquery-3.2.1.min.js', array() , '1.0.0', true);
    wp_enqueue_script('jquery');

    wp_register_script('bootstrap', get_template_directory_uri() . '/plugin-frameworks/bootstrap.min.js', array() , '1.0.0', true);
    wp_enqueue_script('bootstrap');

  wp_register_script('swiper', get_template_directory_uri() . '/plugin-frameworks/swiper.js', array() , '1.0.0', true);
  wp_enqueue_script('swiper');

  wp_register_script('scripts', get_template_directory_uri() . '/common/scripts.js', array() , '1.0.0', true);
  wp_enqueue_script('scripts');

  wp_register_script('custom', get_template_directory_uri() . '/custom.js', array() , '1.0.0', true);
  wp_enqueue_script('custom');

}

add_action('wp_enqueue_script', 'addjs', 999);
Dmitry Leiko
  • 3,970
  • 3
  • 25
  • 42