The problem is that this only works when the widget is present in a sidebar.
If you need some code to run independently from widget, I reason it makes sense to add that code separately from widget class.
And I also need it to work when I call this widget with the_widget() function, for eg. inside a page. I don’t know how could I retrieve the widget options to pass them in the javascript code…
That function takes instance array with widget data. I am not sure about your specifics, but I thinks you can pass whatever you need in there.
Directly called widget has no data, other than passed in instance (or retrieved by itself).
Related Posts:
- Get the sidebar ID in which the current widget was dropped
- Count widgets of a certain type
- Update widget form after drag-and-drop (WP save bug)
- How do register_sidebar() and get_sidebar() work together?
- Add a class to links in the visual editor (how to get old dialog back)
- How to make a script load after Custom Block is loaded in the editor?
- Need help with friendly URL’s in WordPress
- How to remove hardcoded characters from playlists?
- difference between esc_attr(), strip_slashes(), strip_tags()?
- Create Image Uploader for Widget
- How to preserve PHP modifications while upgrading WordPress?
- Widgets vs. Theme Mods
- Widgets not working in Customizr but working in Appearance
- When using the block.getSaveElement hook can you output different markup based on whether or not you are in the edit view or the live page view?
- How Can A Widget With Only One Instance Be Defined?
- Getting $comments outside the comment template
- Limit the Excerpt field in WP-Admin in words
- How to exclude certain widget from showing up on home/front page? [duplicate]
- media_handle_upload weird thing
- Customise search form in the Widget
- Comment filtering (search)
- Prevent WordPress from loading comments
- Infinite-Scroll Plugin and Jetpack Infinite Scroll Plugin – Adding to “Thoughts” Theme
- simple expandable vertical menu, java script problem
- Setting up widgets in wordpress with a unique ID for the after_title argument
- Schedule cron event from widget
- WP_Query with the “offset” argument
- How to Register and Display Widget for Custom taxonomy
- Widgets not showing in my custom theme
- register_sidebar ‘after_widget’ on custom-built widgets not implementing, caused nested widgets
- Add ‘Right Now’ widget to custom dashboard
- How to use get_option() without any filter?
- dynamic external javascript generated using php
- Add filename to attachment page url
- Custom widget select options needs to stay selected after save
- How to display something in a div when the user clicks on a text in another div – no page refresh [closed]
- Custom Widget form function common elements
- Updating Widget options in custom install.php
- javaScript in section of WP API
- How to link external JavaScript files?
- Modify a theme to insert custom widgets?
- add JS to multiple plugin admin pages
- How did I enable atom feeds in a fresh WP3 install?
- How to add just one specific page to widget without plugin?
- Create simple Cookie Box for WordPress
- How to update preview when custom setting changed in my custom widget
- Child Theme – how to add new widget on a specific place?
- how to add custom css and js on wordpress post editor directly without using .php file
- Extending the WP_Widget_Text class
- Warning: Creating default object… when altering Customize panels
- Javascript Solution Remove Specific Tag but leave the rest in a specific DIV
- Fastest way to get the comment and ping total count for a post
- Author Tracking Code!
- want to create a subcategory.php to manage subcats
- window resizing problem
- Adding custom field in all widgets, but at the top of the form, in admin area
- How do I change the markup only of a built-in widget?
- Customize Theme comment template to Insert VoteUp and VoteDown buttons
- Is it possible to make widget return only data (eg, array)?
- Load MediaPlayerElement after Infinity Scroll loads more posts
- Include custom JS without child theme
- Allow a Widget to be used one time only?
- Search widget will search everything in the site, how to limit to only search gallery name
- How to add a do_action on refreshing of WP customizer?
- Disable widgets in customizer for sidebar
- Menu jumping when calling it via PHP
- Unable to edit the “customize” section and the “widget” section is populating unknown code
- Choose sidebars column in widgets.php page [closed]
- Can’t receive $args[ ] to my custom widget
- Organizing the position of widgetized areas in the backend
- Media Upload , file name changed automatically
- how to convert Html block to dynamic widget?
- I’d like to move the Widgets Panel to the bottom of the list in Customizer
- How to get my plug-in, wrote in php, to refresh on its own every 5 minutes?
- Redirect to another page using contact form 7? [closed]
- Custom Login Process
- Create small dashboard widget
- Hook called before text widget save
- Javascript Tooltip not fully working on my wordpress page
- How to narrow the area between buttons on Helium theme sidebar? [closed]
- Where to put coding a validation script for store? [duplicate]
- WordPress Customizer: Check for value of CSS selector and replace it
- How to hide or remove a custom widget area when empty
- Execute function with jQuery if widget added or removed?
- Automatically refresh page if widget is added to page?
- custom field – changing an element or background of id div – different versions not working
- How to submit form data in the same page in WordPress without reloading the page?
- Still desperate about multiple TinyMCEs in widgets – is there any good solution to this yet?
- how to auto fille conatct form 7 when user is logined
- Custom Admin Section
- How to define active widget with js in a customizer
- How to implement custom Javascript to my site
- Multi-site customization
- Why isn’t my custom Javascript showing up in my custom template?
- Slider from different widgets
- Confused about customising widgets
- Edit a custom admin page
- Special characters showing in fallback font
- Pass the post ID
- Widget header unique classes