0

Inside a wordpress plugin : The second enqueued js file isn't read, need I specify something ? Does registering is necessary when several js files are called (enqueued) ?

function atv_internationalization() {
    wp_enqueue_style('atv-translate-css', plugins_url('', ATVTRANSLATE) . '/atvinternationalization.css');
    wp_enqueue_script('atv-translate-js', plugins_url('', ATVTRANSLATE) . '/atvinternationalization.js', array('jquery'), '1.0', true );
    wp_enqueue_script('atv-converturl-js', plugins_url('', ATVTRANSLATE) . '/atv_permalink/replaceurl.js', array('jquery'), '1.0', true);
}
add_action('admin_enqueue_scripts', 'atv_internationalization');
add_action('login_enqueue_scripts', 'atv_internationalization');
add_action('wp_enqueue_scripts', 'atv_internationalization');

atvinternationalization.css and atvinternationalization.js work.

replaceurl.js is well included inside wp footer but the script isn't read or interpreted even just for console.log('something'); Each jQuery file is instantiated like this:

console.log("something"); // works outside jQuery
jQuery.noConflict(); don't resolve problem : It's not a jQuery conflict 
(function($){
    $(document).ready(function() {
        $('body').text("something"); // doesn't read 
    });
});

I checked the good way to directory file .

Must I use get_template_directory_uri() instead, if yes why ? I emptied browser cache many times

Update : This method doesn't solve the problem :

function atv_internationalization() {
    wp_enqueue_style('atv-translate-css', plugins_url('', ATVTRANSLATE) . '/atvinternationalization.css');
    wp_register_script( 'atv-converturl-js', plugins_url('', ATVTRANSLATE) . '/atv_permalink/replaceurl.js', array('jquery'), '1.0', true );
    wp_enqueue_script('atv-translate-js', plugins_url('', ATVTRANSLATE) . '/atvinternationalization.js', array('jquery'), '1.0', true);
    wp_enqueue_script('atv-converturl-js');
    wp_enqueue_script('atv-translate-js');
}
7
  • 1
    If the <script> tag is included in the HTML with the correct URL then it's been enqueued correctly. WordPress has done it's job. If the script isn't working then it's a problem with the script. If your script is the last thing on the page, then (document).ready( may have already run by the time your script is loaded, meaning that it won't run. Aug 29, 2023 at 13:57
  • 1
    what does your browsers dev tools console say? 404? Are there errors? The JS you've included doesn't do anything, the console.log is commented out. This is extremely unlikely to be a WordPress problem if the script tag is in the HTML and points to the correct URL
    – Tom J Nowell
    Aug 29, 2023 at 14:04
  • @jacob-peattie : delete '(document).ready(' doesn't fixed the issue. No there are lot of wp script after .
    – imagIne
    Aug 29, 2023 at 14:23
  • @tom-j-nowell : console.log say nothing , no error. I update my question
    – imagIne
    Aug 29, 2023 at 14:24
  • @tom-j-nowell , I have this error 'Failed to load resource: Operation could not be completed (kCFErrorDomainCFNetwork error 303.)' but I don't think it concerns my problem .
    – imagIne
    Aug 29, 2023 at 14:49

1 Answer 1

0

Problem resolved: Thanks for your time and help. Jquery must be called like that, It's a mistake from me.

(function($){
    $(document).ready(function() {
    });
})(jQuery);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.