First you should use the wp_enqueue_scripts to load your scripts.
add_action( 'wp_enqueue_scripts' , 'javascript_file-exmp' );
Second, be sure to both register and then enqueue your script
Register:
wp_register_script( 'links', plugins_url( 'test.js', __FILE__ ), array( 'jquery' ), '1.0', true );
1.0 is the version, used mainly to avoid caching on when you update it.
true controls whether the script can be called from the bottom of the page rather than in the <head> tag.
Enqueue
wp_enqueue_script( 'links' );
Lastly, as suggested above you should really separate your HTML from your javascript.
Related Posts:
- How to load wp_editor via AJAX
- Getting a custom Gutenberg component’s state from outside that component
- Why my browser keeps loading old version of custom JavaScript files in \divi\js? [closed]
- How do I only load a plugin js on it’s settings pages?
- How can I change my javascript after it has been enqueued? [closed]
- What happened to convertEntities?
- Create Proper WordPress Ajax Request in JavaScript, NOT jQuery
- How do I use WordPress PHP functions in my Javascript code?
- How to avoid redefining requirejs in plugin when another plugin also uses requirejs
- Difference between register_block_type & wp.blocks.registerBlockType
- Has anyone used require.js for handling plugin scripts?
- Can I share predefined fonts from theme_support with a gutenberg component?
- How do I store information in a dynamic block in WordPress?
- W3 Total Cache: Load CSS asynchronously for better PageSpeed score? [closed]
- Pass a php string to a javascript variable
- Problem in loading javascript in footer
- add mediaelement.js plugins into WordPress video player control bar
- Shortcode button dosent work for all posts. Work for first post only
- Get IDs of Images from Gallery Block in InnerBlocks of a Custom Gutenberg Block
- React JSX in WordPress Plugin Development
- Internationalization autocomplete JS variable
- Is there an earlier hook than login_head or login_enqueue_scripts?
- Can someone please tell me what is wrong with my plugin?
- Scripts at the end of the page
- Enqueue WordPress plugin scripts below all other JS
- Can I use custom CSS and js plugin to put JavaScript in to validate my forms
- Time consuming callbacks in customizer
- add image crop function like in wp customizer
- Calculate price and display on woocommerce product single page under price (simple price, variable price) [closed]
- Executing Javascript when a New Post is Published
- Set featured image using javascript in post editor
- Display encrypted content on my website
- Trying to create a private area custom for each user where they upload images to a server [closed]
- wp.media javascript issue with on select
- WordPress + JavaScipt + AJAX + MySQL: insert query for form
- Add custom JavaScript that is a combination of CDN/uploaded files and easily-edited code?
- How to get my plug-in, wrote in php, to refresh on its own every 5 minutes?
- Using TinyMCE in plugin?
- GeoMashup plugin: how to customize cluster markers / icons? [closed]
- How can I remove the WordPress-Version (?ver=5.x) from my plugin
- wordpress add_action() issue in ajax call
- Localizing methods for jQuery append prepend wrap parent
- how to insert a HTML form into a javascript popup?
- Display a consistent Google Plus icon on ALL pages of my site
- Which plugin can do horizontal scrolling of RSS feeds in WordPress [closed]
- get specific value of a array | PHP
- coding a WordPress AJAX Form using PHP to check if User is Logged Out and Show error
- Conditional custom redirect
- Meta slider plugin only works after first refresh – Object has no method ‘flex slider’
- Load CSS files in header of Bones theme?
- how to request a script more than once in wordpress
- How to turn off automatic operation for Nivo Slider?
- How to enqueue some javascript source once per page
- JS Plugin not executing the js correctly. Trying to make all internal links scroll smoothly
- Call javascript functions from each page
- Javascript from Easy-Fancybox place into footer
- Wp-minify doesn’t seem to minify my JS code
- uncaught TypeError: Cannot read properties of null (reading ‘classList’) custom plugin
- How do I minify a plugins CSS/JS code?
- Ajax call not working in wordpress through a plugin
- Javascript fetch on wordpress plugins not working
- Jquery POST Ajax Return null data in wordpress
- Validating ajax search
- Cannot run script properly with my custom plugin
- Overriding inline !important CSS with Javscript code snippet with media query
- Add style to body based on url
- Performing CRUD operations on front end in wordpress
- How to add specific script to WordPress webpage that will working with user input and databases
- Ajax Call not Working in Plugin
- How to create a custom block in Gutenberg with multiple checkboxes?
- Website always load twice on start
- Add external javascript to post template
- Why can I not deregister my style and script on custom post type?
- AJAX update fails for public/non-admin users
- Javascript inserted from Plugin pointing to wrong location
- Speeding up WordPress on a Local Network
- Conditional Fields depending on checkboxes
- How to pass value from WordPress to Javascript
- Number format in thousands on highcharts in wpdatatable plugin
- Facebook Quote Plugin for Blockquote?
- Adding javascript to header of MetroMagazine theme
- Embed Javascript code to registered users only
- Javascript in plugin not working
- Best use adding user generated JS/CSS to a theme with a plugin
- Jetpack Comments Change Placeholder Text
- Media Playlist Plugin
- Adding an onchange event to a custom dropdown menu in WordPress
- How to set up php,javascript and css to allow for our finished product to be displayed within a page?
- Possible jquery / library conflict in plugin usage
- Plugin and javascript placement
- Why won’t the Comprehensive Google Map Plugin load?
- get_option include in my adsense
- Expanding / Collapsing Modules in WordPress Panel
- making a simple plugin
- Javascript as Jquery Function Call?
- How to make a rest style plugin?
- how to show selected options drop down menu values in attributes field in after saving post.php
- Refresh server side rendered block in Gutenberg without changing attributes or its content
- Implementing onSplit/onMerge in dynamic Gutenberg Custom Blocks
- How to get selected variation from URL?