Skip to content Skip to sidebar Skip to footer

Register Js For More Than One Predefined By Id Pages In Script-calls.php

I have this js code (saved as shomz.js file) var shown = true; var parent = document.querySelector('.parent'); var child = document.querySelector('.child'); parent.addEventListene

Solution 1:

Define an array holding your specific ID's. In the if statement you'll just check if your current ID is in your defined array.

// Main Scriptsfunctionregister_js() {

    if (!is_admin()) {
        $url_prefix = is_ssl() ? 'https:' : 'http:';

        /* Get id of current page*/$page_id     = get_queried_object_id();
        /* Compare the desired page's id with the current page's id, if       they match, enqueue shomz*/$ids = array(1, 2, 3, 4);
        if (in_array($page_id, $ids)){
            wp_register_script('shomz', THB_THEME_ROOT . '/assets/js/plugins/shomz.js', 'jquery', null, TRUE);
            wp_enqueue_script('shomz');
        }
        wp_localize_script( 'app', 'themeajax', array( 'url' => admin_url( 'admin-ajax.php' ) ) );
    }
}  

PHP Ref: http://php.net/manual/en/function.in-array.php

Post a Comment for "Register Js For More Than One Predefined By Id Pages In Script-calls.php"