kamilm14
kamilm14

Reputation: 333

jQuery One Page Scroll in wordpress theme

I'm trying to code wordpress template with jquery one page scroll plugin. Can someone help me to understand why the plugin is not working when I add it to my template using functions.php file like this:

  function wpbootstrap_scripts_with_jquery()  {
    // Register the script like this for a theme:
    wp_register_script( 'bootstrap', get_template_directory_uri() . '/bootstrap/js/bootstrap.min.js', array( 'jquery' ) );
    wp_register_script( 'one-page', get_template_directory_uri() . '/bootstrap/js/jquery.onepage-scroll.js' , '', '', true );
    wp_register_script( 'front', get_template_directory_uri() . '/bootstrap/js/jquery.onepage-scroll.js', array( 'jquery' ) );

    // For either a plugin or a theme, you can then enqueue the script:
    wp_enqueue_script( 'bootstrap' );
    wp_enqueue_script( 'one-page' );
    wp_enqueue_script( 'front' );
}
add_action( 'wp_enqueue_scripts', 'wpbootstrap_scripts_with_jquery' );

After including it to footer.php:

<script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/bootstrap/js/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/bootstrap/js/jquery.onepage-scroll.js"></script>
<script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/bootstrap/js/front.js"></script>

plugin works. But I rather want to use the first method than second one. Does anyone know what I'm doing wrong with functions.php?

Upvotes: 0

Views: 289

Answers (1)

Moishy
Moishy

Reputation: 3638

add true at the end to add it to the bottom of the script before the closing body tag

wp_register_script( 'bootstrap', get_template_directory_uri() . '/bootstrap/js/bootstrap.min.js', array( 'jquery' ), '', true );
wp_register_script( 'one-page', get_template_directory_uri() . '/bootstrap/js/jquery.onepage-scroll.js' , array( 'jquery' ), '', true );
wp_register_script( 'front', get_template_directory_uri() . '/bootstrap/js/jquery.onepage-scroll.js', array( 'jquery' ), '', true );

Upvotes: 1

Related Questions