Your code doesn’t work because of a fundamental ordering problem.
You’re hooking into wp_footer. Then you’re registering a script and enqueueing it. Finally, you echo some code.
Here’s the problem, the act of enqueueing a script does not cause an echo of the script code immediately. Enqueueing does just what it says, it sets the script up to be added to the page output at a later time. So your echo of the script code here is too early.
Specifically, the enqueued scripts for the footer happen in the wp_print_footer_scripts call, which is connected to the wp_footer action with priority 20. So you need to enqueue before then, but print your custom script code after then.
So make a new function. Hook it to the wp_print_footer_scripts action. Then move your echo code into that, but leave the enqueue code where it is.
Related Posts:
- ajaxurl not defined on front end
- How to include jQuery and JavaScript files correctly?
- jQuery in header or footer
- Using function from enqueued .js file in theme in plugin?
- Why does WordPress use outdated jQuery v1.12.4?
- How to add a javascript snippet to the footer that requires jQuery
- How to Add a .js file Only in one specific Page Dynamically to Head
- Use js script from one plugin in another plugin
- What is the difference between these two methods of writing $ instead of jQuery in WordPress [closed]
- How to avoid loading same script twice?
- WordPress custom taxonomy check box to dropdown
- jQuery does not enqueue for my purpose… (before an inline script in the footer)
- should i be checking for jquery before enqueing it in a plugin
- How to enqueue scripts in right way in a plugin?
- unable to wp_enqueue_script(‘suggest’);
- Ajax: Populate with content from a post’s ID not working – duplicating current page html instead
- Loading Images from Javascript on the Front End
- Add a Script button in W3 Total Cache plugin not working due to conflicting jQuery version
- Script work on non logged in user but not work for logged in user?
- Loading jQuery library from WordPress admin
- How to get the value entered in the input field in wordpres
- How react js and other Javascript Technologies works on WordPress plugin?
- Replace “content-area” of themes 404 page with plugin?
- Autoloading & Namespaces in WordPress Plugins & Themes: Can it Work?
- Javascript not being loaded only in custom taxonomy template
- wp_ajax add_action fuction won’t fire on custom jQuery action
- Filterable posts using categories
- How to get values from Tinymce visual editor popup?
- set a custom post type to a taxonomy term programmatically in metabox
- Ajax Response Error | just getting error as the response
- Custom premium registration form and profile page for a WordPress Web Application
- redirect_to how to make it simply work with get parameter or similar?
- Enqueue scripts based on site.
- My enqueue admin style function doesn’t work because of ?=ver
- Determine if the current page, is being edited
- Can i prevent the effect of the_title filter on the dashboard’s posts/pages titles?
- replacing jquery google cdn with a new version dynamically
- How do I make two shortcode use the same id and increment it when I use them multiple times?
- How to enqueue an external Javascript file to Frontpage footer
- WordPress function is not called and ajax return 0
- Is it possible to modify an Elated plugin portfolio-list template in such a way that it will not conflict with future plugin updates?
- How to embed or integrated a custom WordPress Widget into the theme?
- Post Pagination does not working on WP-Query
- How to destroy or dispose wordpress uploder/manager?
- Ajax call not working with
- How to CRUD from wordpress database in wordpress theme?
- Woocommerce Custom Checkout
- Dynamic sidebar areas not working on the Theme Customizer
- Caption Shortcode: what filter to change the image size?
- Looping single post in a theme
- Font Awesome stopped showing icons, shows &# text instead [closed]
- How can I add the Post ID to Class Name in Jquery?
- Enqueue script not working
- Merge Codes using redux framework
- To remove rendering of menus and header, plugin or theme?
- To remove rendering of menus and header, plugin or theme?
- Managing Custom Designed Content
- Template file structure , wordpress hook for altering the template
- WordPress permalink setting
- Custom theme and plugin updating
- Issue on Getting Images URL of the Post Gallery
- Best practice: What belongs in theme and what in plugin for large eCommerce website
- How can I add recent posts to menu like mashable
- Is there a general way to get a themes primary colour?
- variable created in page.php is null inside of header.php
- Issue on Getting WP Gallery Items In cpt-single.php As Attachments
- Generate activation url
- Adding class to the parent of current-post-ancestor / current-menu-parent / current-post-parent
- problem with blank page
- How do I call the dashboard’s sortable javascript in a plugin page?
- How to Register/Link to .js Files in WordPress Dynamicaly in Header.php
- grouping my widgets wordpress
- Display Data’s metabox in page
- Updating Style From WP Options Setting Page
- Cannot echo a JS variable to a jQuery plugin coming from wp_localize_script
- enqueue script if page is not equal to
- Ajax functions – no access to wp-admin.php only online
- Create and style menu
- WordPress Beginer to Guru [duplicate]
- Saving multiple fields as array
- Page reload occurs before request finishes
- Why does this fail: Disabling plugins enqueue_script() in functions.php
- If I want to create new taxonomies (e.g. Project / Documents / Etc…) is it better to create them in the theme’s functions.php or within a plugin? [duplicate]
- Enqueue Script in custom plugin before other
- How to add something after a function
- append code after the_content not working
- How can I make my website with wordpress having on-spot editing feature as compared to concrete5 CMS?
- Problem with Poedit [closed]
- Best Way to Inventory the Media Library of a 200+ Multisite Installation?
- Theme now uses require.js and enqueue script no longer works
- How to only Load scripts on variable products page
- Using tag or inline style attribute?
- How do I use (or mimic) document.getElementById() on a page loaded from WordPress database?
- how to insert content into wp_head after loop_end
- Integrating WordPress Content into a jQuery Slider
- Is Explicit Versioning a better alternative to Semantic Versioning for wordpress?
- Invalid Menu Items
- how many rupee or dollar charge to client to make theme [closed]
- Gutenberg text field validation
- how to catch a data from a array in WordPress