How to call an object method loaded by a plugin using a “Custom HTML” Script?


So, I have a Map plugin on my WordPress site. Whenever the window is resized, the plugin calls a method that also resizes the map and it gets just fine. But when the plugin is loaded on mobile, the canvas size does not load correctly, and the plugin does not resize the map because there can’t be any resizing happening on the mobile browser.

The object is loaded and listed on Window objects, on devtools. What I want is to inject a script on the page that could find the object and call the method upon it…

Is it possible? I’m sorry, I’m pretty newbie with dev…

Thanks in advance, anyway!

1 Comment
  1. I think to achieve this, you’ll need to make sure that the object is accessible on the global scope (i.e., it is a property of the window object), and that the method you want to call is a property of that object.
    You can add a script tag with your custom JavaScript code to your page, using the “init” php hook. In this script, you could try using the window.onload event to ensure that the plugin has loaded and the object is accessible before attempting to call the method on it.
    Here is a sample code to call a method, you can use it as reference and update it according to your plugin and object.

    window.onload = function() {
    if (window.myPluginObject && typeof window.myPluginObject.myMethod === “function”) {

    Additionally, it would be good to check for the device and call the function only for the mobile devices.

    Please do let me know if you have any questions or need further assistance, and I’ll be happy to help!


This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer