Save your JavaScript code out to a separate file within your plugin directory. Then use this code to load the file using the wp_enqueue_script()
function.
function smooth_scrolling_links() {
if ( !is_admin() ) { // Don't load if in the admin screen
wp_enqueue_script('Smooth-Scolling-Links', plugin_dir_url(__FILE__) .'-YOURFILENAME-.js');
}
}
Obviously replace the -YOURFILENAME-
with the file name that you created.
You may also need to modify your JavaScript slightly to comply with the jQuery noConflict wrappers
. You can see the codex document here with a full explanation.
Edit to show jQuery noConflict wrapper
You also need to change –
$(document).ready(function() {
$().smoothscrolling();
})
To this –
jQuery(document).ready(function(){
jQuery(#smoothscrolling) ...
});
Related Posts:
- force enqueue script to be first in order of prominence
- Custom plugin giving: wp-admin/admin-ajax.php 400 (Bad Request)
- Check javascript file Proper way in functions.php
- How do I use WordPress PHP functions in my Javascript code?
- How to create popup same as wordpress popup feature
- Pass a php string to a javascript variable
- Problem in loading javascript in footer
- JQuery not working in my plugin [closed]
- Best approach to fetch data from wp options to js file or php file
- Can someone please tell me what is wrong with my plugin?
- wordpress site | All-in-one-cufon IE Issue
- Change upload folder for a CPT
- Time consuming callbacks in customizer
- Modifying a .js Function for Print [QZ Tray, WooCommerce POS]
- Redux Framework: Page freezes on typing in Editor
- Using window.onload with Ubermenu
- “Conflict” with jQuery (or its plugins)?
- wordpress add_action() issue in ajax call
- Localizing methods for jQuery append prepend wrap parent
- Why does my jQuery plugin show up as text in WordPress?
- JQuery needs to be defined in , but Gravity Forms is defining it in the
- Disable submit button order
- Load CSS files in header of Bones theme?
- Call javascript functions from each page
- Javascript from Easy-Fancybox place into footer
- Jquery POST Ajax Return null data in wordpress
- login form should redirect to register page for in 1st login next time it should redirected to home page
- Overriding inline !important CSS with Javscript code snippet with media query
- Get the link title attribute and send it google analytics as custom label via google tag manager using beehive pro for WordPress
- How to properly enqueue jQuery knob on WordPress without conflict?
- Ajax Call not Working in Plugin
- How to get a specific string from a url
- Does anybody know how to insert a complete jquery plugin into a wordpress elementor-page?
- JS working when used normally but not in wordpress
- Website always load twice on start
- How to solve Blocked a frame with origin from accessing a cross origin frame error in wordpress?
- Custom plugin giving: wp-admin/admin-ajax.php 400 (Bad Request)
- show-hide based on select option jquery wordpress
- Javascript in plugin not working
- Possible jquery / library conflict in plugin usage
- Ajax, jQuery and WordPress
- Why won’t the Comprehensive Google Map Plugin load?
- get_option include in my adsense
- How do I output user_registered time in my correct timezone?
- Ajax in Plugins: returns the whole page
- Element works, but not on wordpress site [duplicate]
- Load css classes after using ajax calls
- FacetWP: Plugin breaks button/modal functionality inside searchable content area
- TypeErrors with Yoast, jQuery in conflict?
- Javascript as Jquery Function Call?
- Count div with class (.length) only shows 0 [closed]
- Pass PHP variable to javascript
- A better way to override plugin’s JS files?
- How can I reduce the amount of files loaded/included per plugin?
- Is dynamic forms/entries possible in Widget?
- Dequeue / Deregister script and replace it with a new plugin
- How to load default scripts included with WordPress correctly?
- Ajax with jQuery UI dialog not working
- Localiztion in javascript
- scrolltop always 0, can’t trigger script
- Bootstrap Drop Down menu is not working
- Override Plugin Script Fucnction in WordPress
- How to hide CSS by default and show on button press
- jquery tinymce and bundled wp plugins
- How to get DEFER or ASYNC attribute to appear when I add a stylesheet with wp_enqueue_style from a plugin? [duplicate]
- Jquery plugin not working on single pages
- How to include this jQuery File in wordpress?
- a weird attribute on every html tag
- How to add an element right after the article using jQuery?
- how to prevent all css and javascripts files from loading
- Close Fancybox, sumbit form data and redirect
- I changed .live() to .on() but change is not reflected on the server
- Save user total active time after login in wordpress [closed]
- jQuery code didn’t run on my plugin
- The Events Calendar Plugin – List View Background Colour Issue [closed]
- Using AJAX to run SQL statement and populate dropdown
- WordPress slider that allows image, headline, text, and button?
- Adding a jQuery modal dialog to the admin area
- Wp-minify doesn’t seem to minify my JS code
- Ajax call not working in wordpress through a plugin
- Why do I need to reload the page for WordPress to see the new custom field added with jQuery
- Cannot run script properly with my custom plugin
- Performing CRUD operations on front end in wordpress
- How to add specific script to WordPress webpage that will working with user input and databases
- 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
- WordPress Ajax request “Failed to load resource: the server responded with a status of 400 ()”
- Conditional Fields depending on checkboxes
- Adding javascript to header of MetroMagazine theme
- Media Playlist Plugin
- Adding an onchange event to a custom dropdown menu in WordPress
- How to add jquery to my custom post type wp plugin
- Like/Dislike Bar not working when updating
- jquery-issue: cannot load the basic jquery
- making a simple plugin
- JQuery UI plugin not working in IE7?
- Jquery based image accordian plugin
- wordpress jquery is not defined because the head tag is empty
- how to show selected options drop down menu values in attributes field in after saving post.php