• Hello WordPressions,

    Can you guys please let me know how can i write below code in wordpress recommended way.

    // Always use wp_enqueue_scripts action hook to both enqueue and register scripts
    add_action( 'wp_enqueue_scripts', 'enqueue_and_register_my_scripts' );
    
    function enqueue_and_register_my_scripts(){
    	if (!is_admin()) {
    
    	wp_register_script('jeasing', get_stylesheet_directory_uri() .'/js/jquery.easing.js', array('jquery'), '1.3', true);
    	wp_enqueue_script('jeasing');
    
        // Use get_stylesheet_directoy_uri() if your script is inside your theme or child theme.
        wp_register_script( 'hover-animation', get_stylesheet_directory_uri() . '/js/hover-animation.js', array('jquery'), true );
    
        // Let's enqueue a script only to be used on a specific page of the site
        if ( is_page( 'portfolio-1' ) ){
    
            // Enqueue a script that has both jQuery (automatically registered by WordPress)
            // and my-script (registered earlier) as dependencies.
            wp_enqueue_script( 'wds-isotope', get_stylesheet_directory_uri() . '/js/isotope.pkgd.min.js', array( 'jquery', 'hover-animation' ) );
    
    		wp_enqueue_script( 'wds-portfolio', get_stylesheet_directory_uri() . '/js/wds-portfolio.js', array( 'jquery', 'hover-animation' ) );
        }
      }
    }

    Thanks in advance.
    Suresh Patel

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Best pratic to include scipt’ is closed to new replies.