Skip to content Skip to sidebar Skip to footer

Register Js For A Defined Page In Script-calls.php

I have this js code var shown = true; var parent = document.querySelector('.parent'); var child = document.querySelector('.child'); parent.addEventListener('mouseenter', function

Solution 1:

Just wrap your script enqueueing function call with an if condition checking whether the current page's id matches the id of the side on which you want the script to be enqueued or not.

// Main Scripts
function register_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*/
        if(YOUR_ID == $page_id){
            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' ) ) );
    }
}

Post a Comment for "Register Js For A Defined Page In Script-calls.php"