0

I am trying to load an external library to the admin section of my website. On the front end it is pretty easy to load.

<head>
 <script src="externalLibrary.com"></script>
 <script src="externalLibrary.com"></script>
 <script src="externalLibrary.com"></script>
 <script src="externalLibrary.com"></script>
 <script src="externalLibrary.com"></script>
 <script src="externalLibrary.com"></script>
</head>

On the back-end we don't have access to the head section so the library links have to be loaded from an external file.

function myCustomScript($hook) {
 
    wp_enqueue_script( 'admin-js', plugins_url( 'admin-columns/js/admin.js' , dirname(__FILE__) ) );
}
add_action('admin_enqueue_scripts', 'myCustomScript');

The external file loads perfectly, I just need help making the urls available in the external file.

This is what I have tried in the js file

var sc = document.createElement("script");
sc.setAttribute("src", "https://getfirebug.com/firebug-lite.js");
sc.setAttribute("type", "text/javascript");
document.head.appendChild(sc);
document.getElementsByTagName("head")[0].appendChild(sc);
5
  • 1
    you should be enqueing on the frontend too, not just the backend, if the external file loads perfectly, what's the issue? You mentioned making the URLs available to the external file, what does this mean? Can you describe using other words? What are the URLs referring to? Is this question asking how to load and use firebug lite from CDN? Right now what you're doing is already the answer to your question
    – Tom J Nowell
    Commented Jul 21, 2021 at 14:04
  • Note that if you need dev tools to debug issues on a mobile device, you can connect to that device remotely or via a cable using Chrome dev tools or Safaris develop menu, something like firebug lite is unnecessary
    – Tom J Nowell
    Commented Jul 21, 2021 at 14:06
  • On the front end I don't need to enque because I place the script tags in the head section of the header. I need to enque on the back end because we don't have access to head section. To make it easy I should just be able to write out the urls externallibrary.com and when the external js file loads I should have access to the external library. Unfortunately it doesn't work that way. The console log error that I get is that https has been declared already when I load more than one url.
    – Ragnaboy
    Commented Jul 22, 2021 at 5:37
  • I am trying to load firebase. <script src="gstatic.com/firebasejs/8.6.1/firebase-app.js"></…> <script src="gstatic.com/firebasejs/8.6.1/firebase-analytics.js"> </script>
    – Ragnaboy
    Commented Jul 22, 2021 at 5:49
  • KISS, my apologies for wasting your time. After struggling with this from the begining of the month and reading your comment 5 times I have figured it out. Instead of enqueing the url from an external file in wordpress, i can just enque the url straight from firebase.
    – Ragnaboy
    Commented Jul 22, 2021 at 6:03

0

Your Answer

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

Browse other questions tagged or ask your own question.