• I have found a tutorial on initializing the wow.js inside of WordPress but struggling to get it to work. Can anyone please advise?

    I have added the following to functions.php:

    //* Enqueue Animate.CSS and WOW.js
    add_action( 'wp_enqueue_scripts', 'sk_enqueue_scripts' );
    function sk_enqueue_scripts() {
    
        if ( is_home() || is_archive() ) {
            wp_enqueue_style( 'animate', get_stylesheet_directory_uri() . '/css/animate.min.css' );
    
            wp_enqueue_script( 'wow', get_stylesheet_directory_uri() . '/js/wow.min.js', array(), '', true );
        }
    
    }
    
    //* Enqueue script to activate WOW.js
    add_action('wp_enqueue_scripts', 'sk_wow_init_in_footer');
    function sk_wow_init_in_footer() {
    
        if ( is_home() || is_archive() ) {
            add_action( 'print_footer_scripts', 'wow_init' );
        }
    
    }

    When viewing page source on webpage, the links work correctly. The bit I’m struggling with is when adding:

    //* Add JavaScript before </body>
    function wow_init() { ?>
        <script type="text/javascript">
            new WOW().init();
        </script>
    <?php }

    Am I missing some tags? my script (footer.php):

    <div id="footer">&copy;<?php echo date("Y"); echo " "; bloginfo('name'); ?></div>
    
        </div>
    
        <?php wp_footer(); ?>
    
    function wow_init() { ?>
        <script type="text/javascript">
            new WOW().init();
        </script>
    <?php }
    </body>

    Thanks for looking.

Viewing 1 replies (of 1 total)
  • Hi keljnr,

    Why don’t you do the whole initialisation for WOW within functions.php? This can be done quite simply:

    wp_enqueue_script( 'wow', get_template_directory_uri() .  '/js/wow.min.js', array( 'jquery' ), true );
    
    		wp_enqueue_style( 'animations', get_template_directory_uri() . '/css/animate/animate.min.css' );
    
    		wp_enqueue_script( 'wow-init', get_template_directory_uri() .  '/js/wow-init.js', array( 'jquery' ), true );

    You then don’t need to do any initialisation in footer.php, and the script is available for use throughout the website.

    Hope that this helps.

    Bob

Viewing 1 replies (of 1 total)
  • The topic ‘Initiating wow.js inside of WordPress’ is closed to new replies.