The post editor is really not meant for inserting functional code like JavaScript into the page.
Anything you put through the post editor will get run through wpautop() before output, which is what adds the paragraph tags — even if you enter it via the Text mode. I’d suggest outputting your JavaScript via a hook on the page instead of via the post editor.
Something like this:
/**
* Output JS to the page head.
*/
function output_head_js() {
?>
<script type=“text/javascript”>
$( ‘#gosearch’ ).click( function() {
…
});
</script>
<?php
}
add_action( 'wp_head', 'output_head_js' );
Related Posts:
- jQuery plugin only in one page/post
- How to fetch serialized data from wordpress options
- Add jQuery to WordPress page
- How do I use WordPress PHP functions in my Javascript code?
- Disable wordpress from including jQuery in the head section
- What’s the point of using WordPress’s built in admin-ajax.php?
- Admin-ajax.php is dying “0” without processing function
- Plugin jQuery version VS Theme jQuery version: search for best practice
- Adding a jquery script to plugin contact form 7
- jQuery Plugin to use WordPress functions in AJAX request
- how to include a simple jquery file into a wordpress plugin
- Pass a php string to a javascript variable
- Calling JavaScript file with Custom Plugin
- Problem in loading javascript in footer
- JQuery not working in my plugin [closed]
- Using jquery migrate for plugins incompatible with jquery 1.10.2
- Notepad sticky plugin
- Loading jQuery UI in the head
- How can I implement an Add to Collection function on my Image Gallery to be downloaded later?
- Form isn’t inserting data into database with ajax plugin
- custom changes removed after plugin update
- Adding a slider captcha to the comment system
- How to put JQuery/Ajax inside shortcode?
- Plugin for a text modal box [closed]
- Can someone please tell me what is wrong with my plugin?
- Is there a way to set the default active tab on Post UI Tab pluggin?
- looking for navigation plugin (accordion) [closed]
- WordPress function not being called from jQuery method
- Need to change url paramenter of share product pintrest [closed]
- How to tie dark mode with prefers-color-scheme webkit? [closed]
- Time consuming callbacks in customizer
- jQuery for custom plugin not working with Divi theme
- How to prevent plugins from loading jQuery
- JQuery plugin that works with Google 1.10.2 and not with WordPress 1.10.2
- Loading a purchased jquery plugin in a wordpress theme
- Post Comments with Ajax in WordPress
- Create shortcode to echo javascript
- Integrating jQuery Datatables with Editor into wordpress admin
- how to insert data in wordpress table usnig jquery ajax
- Jquery NoConflict Problem
- AJAX fileupload – TypeError: not a function ajaxSubmit()
- How does one include the JQuery UI plugin to wordpress and enque it correctly in a plugin form?
- Remove Yoast jQuery from front end
- Is there a function to list all uploaded images? How can I add one?
- How to best create a jQuery Slider to display a native wordpress gallery?
- How to remove js ui library added by default by wordpress
- Creating a widget and missing jQuery
- Stop wordpress from requesting external jquery from googleapi
- Api external with wordpress
- JQuery needs to be defined in , but Gravity Forms is defining it in the
- Why do I get jQuery reference error / undefined when changing name of plugin file?
- Custom meta box with jQuery.sortable custom post type list
- How to prevent tabs from opening all at once
- Separate jQuery for Individual Comments?
- FancyBox JS stopped working on multiple sites. Custom plugin responsible. Urgent help needed
- jQuery(‘#news-ticker’).cycle is not a function
- Javascript from Easy-Fancybox place into footer
- WordPress plugin isn’t loading completely
- jQuery slider widget similar to cnet.com
- Problems with jQuery and is_admin()
- FacetWP breaks jQuery events
- login form should redirect to register page for in 1st login next time it should redirected to home page
- WP Ajax DB issues
- Get the link title attribute and send it google analytics as custom label via google tag manager using beehive pro for WordPress
- jQuery Ajax not loading page with ACF fields
- Mixed content error after adding SSL certificate
- Website always load twice on start
- Hide button after form submit and save state to localstorage
- Uncaught TypeError: Cannot read property ‘cycle’ of undefined
- myStickymenu hide on scroll up to certain Y values
- How to solve Blocked a frame with origin from accessing a cross origin frame error in wordpress?
- Overwrite js code using WP_Footer
- jquery plugin won’t fire when hamburger class element clicked
- Custom plugin giving: wp-admin/admin-ajax.php 400 (Bad Request)
- Overwriting Plugin’s Ajax callback function from theme
- jQuery to show icon after .hide
- Can’t find variable is_single in my jQuery plugin
- Specific plugin script not working on subdomain
- Not getting result using ajax on wordpress
- Theme Load Error
- How to Add Jquery FullCalendar in wp plugin in admin
- Plugin program: JQuery not working in this plugin
- AJAX doesn’t pass variables to the php function in the plugin
- Ajax, jQuery and WordPress
- Hyperlink to execute PHP
- How to get site homepage from plugin?
- jQuery loaded in wrong order for non-admin page views only
- Trying to override/intercept a PhotoMosaic gallery link in WordPress using jQuery
- PHP and Jquery pass value from form. Update function on DataBase
- WordPress plugin ajax post parameter
- Plugin use of ajax/jquery depending dropdown
- How do I output user_registered time in my correct timezone?
- Ajax in Plugins: returns the whole page
- Shortcode return is printing a 1 afterward
- Load css classes after using ajax calls
- How to resolve these findings from security audit
- Integrating WordPress Content into a jQuery Slider
- Animate like Stack exchange frequently asked questions [closed]
- Change page content based on dropdown selection
- How to add an active state class to my info box