That’s expected behaviour, since you’re calling wp_enqueue_script
mid-page, so at that point the <head>
ship has sailed, and the only other option is to enqueue in the footer, which is fine.
I didn’t spend too much time reading the actual script that you’re enqueuing, but it seems like it it’s doing some document.write()
as soon as it’s loaded, which is why you’re probably seeing the output in the footer.
To solve your problem I would rearchitect the script a little bit, turn it into a function that accepts an element and then in your widget output call that function:
<div id="my-widget-id"></div>
<script>
jQuery(document).ready(function($){
my_function($('my-widget-id'));
});
</script>
That way the script will wait for your .js file to load in the footer, and then call its function passing the widget ID, which you can hopefully insert your output into with $.html()
.
Hope that helps!
Related Posts:
- Conditionally enqueue a widget’s script/stylesheet in HEAD (only when present on page!)
- Plugin upgrading: Widget settings
- How can I make my custom shortcode work in a Custom HTML Widget?
- How to pass JavaScript variable to PHP in wordpress widget?
- Is dynamic forms/entries possible in Widget?
- How do I add a widget programmatically to a newly created site (WPMU) within a plugin?
- WordPress widget / plugin….fields not appearing in my widget
- Created Widget Not Showing up on Admin Panel
- How do I register a stylesheet inside a WordPress widget?
- Detect if a plugin was included in a certain page
- Passing $this->get_field_name() to javascript
- Can I use a form in a dashboard widget?
- Ajax gives 400 error
- Archive – same title for the first two posts
- Ajax contact form widget plugin data not insert in database
- WordPress Widget – Saving multidimensional arrays into $instance
- Widget’s container?
- strange shortcode error: does shortcodes requires any dependency?
- WordPress Widget Not Saving Instance
- How to set the default value as the saved value once a form of widget is saved?
- My widget won’t update its values when save is clicked
- How to add captcha to publish widget
- Table of contents (TOC) plugin is not showing header tag
- Widgets are not displaying in the admin panel
- The styles in the recent posts widgets plugin not working
- Using foreach loop for `$instance` of form and update array widget iteration
- One time call to external API in widget
- Widget outputs the value but doesn’t save anything inside the textarea
- WordPress Widget: Is it possible to make the form dynamic without updating?
- Plugin Works, but Widget Doesn’t
- Widget redirecting to home page
- WordPress plugin not eching popular posts
- What are the downsides of using bootstrap in plugin development?
- What can I do to customize a widget provided with this plugin? from where have I to start?
- Custom Dynamic Tag in Elementor not showing image
- Does WP identify plugin by plugin name or plugin_basename?
- switched from query_posts to WP_query, not working now?
- Making a plugin only available on the front-end for the logged in super admin
- Rotate Widgets or Content Blocks every x sec/min
- Multi language site [closed]
- How to style the RSS wordpress?
- How can I disable widget from being visible on some pages?
- Create entire wordpress as a github repositery?
- Help With MySQL to WPDB Query Conversion
- When to load auto-login code?
- AJAX search posts and pages
- How to find the origin of a file upload from within wp_handle_upload?
- How to display more than one instance for a widget?
- How would I go about creating a user ranked post popularity page?
- CSV file generation failing
- Updating the Drag-To-Share eXtended share URLs?
- Custom random quote widget breaks when used in multiple sidebars
- finding whether request is for post, and post id
- Building plugin with changeable custom post type values…advice needed
- Hooking in to replace the Sidebar/Widget areas
- How to get all of the activate_plugin action parameters?
- __callStatic method handler passed to add_action causes bug in PHP
- Enqueue WordPress plugin scripts below all other JS
- Display update notification messages like ‘What’s New’
- How to add Internationalization in WordPress using Javascript/React?
- Do widget options need to be escaped widget()?
- CRUD and Frontend show from a custom table without shortcode
- How to get specific setting by settings_fields()?
- Save / Show multi line text in metabox
- Creating mySQL procedure with $wpdb
- how to disable blockrenderAppender inside all Innerblocks?
- why doesn’t this update part of this plugin work? it take me to nothing here page
- Redirection of users away from wp-admin (but not administrators)
- WordPress Gutenberg react make import of __experimentalUseInnerBlocksProps which is no more experimetal
- Using a custom plugin to capture input data via Ajax and PHP
- Python with wordpress plugin
- Display post lists in 2nd paragraph
- Map Custom Registration Fields to WordPress User Roles
- Not able to add option in Sub-Menu under page
- How to stop activating a plugin and show admin notice when dependent plugins minimum version is not met
- Using a post-signup hook to get user details
- How to apply a patch via plugin?
- Fixing WordPress’s Bug (failed to send buffer of zlib output compression) results in “White Screen of Death”
- Disable woocommerce cookies and delete cart data automatically
- link bbpress forum discussion to blogposts
- Install Plugin via Code
- code is working properly in Core PHP but writing coding in WordPress
- Combine scripts from all extensions of the plugin when an extension is activated
- Creating a custom post type, adding custom meta fields, preventing all future editability of posts of this type
- Prevent duplicate records in plugin table
- How to add media field to WP_Widget form function?
- Send Custom welcome email to specific user group
- woocommerce payment gateway callback not firing [closed]
- How to modify WCMP Rest API response?
- Fetch Children of Grouped Products Inside WooCommerce Product Loop
- White page by using filter template_include
- How to fetch products with the price in a page on woocommerce using a form or live search with php
- Making a Template for a CPT created by a plugin
- Woocommerce dependent plugin
- WordPress.org Plugin Directory doesn’t recognise screenshots [closed]
- External CSS in WordPress Plugin [closed]
- How to check current user before all actions and filters?
- Owl Carousel2 image not displaying full width when using Stretch row and content, Stretch row and content(no padding) in wordpress
- User Session and Stored Cookies not get removed
- New databes tables with – WooCommerce – for developers [closed]