wilded
8/13/2018 - 8:05 AM

Add Custom Jquery Scripts in Wordpres

Add Custom Jquery Scripts in Wordpres

https://benfrain.com/how-to-easily-add-jquery-scripts-to-a-wordpress-child-theme/

Add @ functions.php of child theme:

if ( !is_admin() ) { // instruction to only load if it is not the admin area
    // register your script location, dependencies and version
    wp_register_script('custom_script',
        get_bloginfo('stylesheet_directory') . '/js/custom_script.js',
        array('jquery'),
        '1.0' );

    // enqueue the script
    wp_enqueue_script('custom_script');
}

Make sure to add jquery functions like the following template:

jQuery(document).ready(function($) {
    //$( "div.hero-search__content" ).replaceWith( "<h2>New heading</h2>" );
    $( ".hero-search__title" ).replaceWith( "<h2>New heading</h2>" );
});