A client side scripting language useful for making interactive web sites

learn more… | top users | synonyms

40
votes
2answers
15k views

What is the preferred way to add custom javascript files to the site?

I've already added my scripts, but I wanted to know the preferred way. I just put a <script> tag directly in the header.php of my template. Is there a preferred method of inserting external or ...
8
votes
1answer
5k views

How to add defer=“defer” tag in plugin javascripts?

I couldn't add defer tag in plugin javascripts. Google developer pagespeed test suggests me to add defer tag in contact form 7 javascripts. This is how contact form 7 includes javascript in header. ...
10
votes
2answers
1k views

Does the functions.php file ever get called during an AJAX call? Debug AJAX

Trying to figure out an issue a fellow programmer is having. I was wondering if the functions.php file get called at all when you do admin side AJAX? I know that when you do an AJAX call a part of ...
6
votes
1answer
627 views

How to load wp_editor via AJAX

Does anyone know how o load wp_editor via AJAX in WordPress? My markup and editor is getting loaded properly but editor controls are not getting loaded properly, it may be because Javascript is not ...
1
vote
1answer
288 views

wp_enqueue_script isn't connecting my custom js file

I am using wp_enqeue_script to link to a custom.js file in my plugins folder. However I am expecting a link to show up on the page but it doesn't is there something else I am supposed to other than ...
1
vote
2answers
1k views

How to trap “Publish” button to check for meta box validation?

I'm trying to do some form validation on my custom meta box, and I remember somewhere reading about some javascript function to disable/enable the Publish button - except I can't find it. How do I ...
2
votes
1answer
4k views

Comment form validation

How can I set the validation rules for the comment field? I change the value of commenter name/e-mail/homepage onmouseover and onblur (I use this instead of labels - so if the field is empty it ...
9
votes
3answers
7k views

Loading scripts only if a particular shortcode or widget is present

I needed a way to filter a page/posts content before it was loaded so I could add scripts to the header if a specific shortcode was present. After much searching I came across this on ...
8
votes
3answers
6k views

Validating Custom Meta Box Values & Required Fields

Something which I have never seen covered is the best way to validate that specific form fields are filled out correctly for custom post type meta boxes. I am looking to get expert opinions on how ...
8
votes
5answers
5k views

Including jQuery and JavaScript files the correct way

I'm having some trouble with this. I'm not sure how to do it the correct way, and I read so many different techniques and ways to do it that I don't know what to make of it. Some questions and ...
10
votes
2answers
1k views

pass object/JSON to wp_localize_script

I've got a working piece of javascript that contains an object literal. But I need to localize it, and I'm ytrying to figure out how to rewrite it so that I can get wp_localize_script() to accet it, ...
2
votes
4answers
3k views

Adding a class (arrows) to main menu links that have children?

I'm wondering if it is possible to add different classes to second/third/fourth/etc-level items that have children in Appearance > Menus tree? That's how I call the menu: <?php $menu_args = ...
12
votes
4answers
1k views

Could the WP script/style loader be used to concatenate and gzip scripts and styles in the front-end?

WP has a nice javascript loader included in wp-admin: http://core.trac.wordpress.org/browser/tags/3.0.4/wp-admin/load-scripts.php and a CSS loader: ...
1
vote
4answers
9k views

How can you check if you are in a particular page in the WP Admin section? For example how can I check if I am in the Users > Your Profile page?

I'm building a plugin and I want to add bits of javascript in the admin head but only for certain admin pages. I don't mean pages as in a WordPress page that you create yourself but rather existing ...
6
votes
2answers
512 views

Modifying a JS file with data from plugin settings

I have a plugin that, among other things, has a javascript file that requires a few user specific settings. What would be the best way to get those settings into javascript from the plugin's settings ...
3
votes
1answer
2k views

How do I get the $handle for all enqueued scripts?

Is there some way to get the $handle for each script that has been enqueued? Is there some array that holds all the handles so that I can loop through it and do something using each $handle?
2
votes
1answer
421 views

Ajax template: how to handle head section

I know it's easy stuff, but I'm new to this and I can't understand which is the best approach. Background The template I'm working on is a dual theme Desktop/Mobile, UA Sniffing based. Now I just ...
6
votes
1answer
3k views

Register and enqueue conditional (browser-specific) javascript files?

The WP.SE community has always advised the use of wp_register_script and wp_enqueue_script for adding scripts in a theme/template (and likewise, wp_register_style and wp_enqueue_style for ...
2
votes
4answers
3k views

Asynchronous Javascript Loaders

I'd like to take advantage of loading my scripts while the page is loading. ie. Yepnope, head.js etc... But I also want to be able to enqueue the script so other plugins don't try adding their own. ...
6
votes
1answer
262 views

Executing Javascript When a Widget is Added in the Backend

I have widgets that have javascript controls attached to them. If the widget is present when the widget admin page loads, the controls work correctly. When I add a new widget, they do not work ...
6
votes
2answers
4k views

How to dequeue a script?

Wordpress has wp_enqueue_script() but not a wp_dequeue_script() function, so what would be the best way to dequeue a script? I'm using LAB.js to load all of my scripts rather than enqueueing them ...
1
vote
9answers
427 views

Graphing libraries for WordPress [closed]

I had asked question like this long ago at WPTavern and it fizzled. Hope it fares better this time. :) Drawing graphs can be done with multiple methods (generating image files, JS, Flash) and there ...
0
votes
1answer
2k views

How do I add custom attributes to javascript tags in Wordpress?

I am looking to enable CloudFlare's RocketLoader feature that enables asynchronous loading of Javascript for my Wordpress site. The problem, however, is that there is one plugin for that I want to be ...
3
votes
1answer
1k views

Instantiate TinyMCE via JS ( rather than PHP/wp_editor )

Once a page has loaded, how do I create a TinyMCE editor? Putting a wp_editor call in an AJAX request then displaying it gives this: Visual and text tabs are nonfunctional, no toolbar, no active ...
0
votes
2answers
2k views

Javascript included but alert() function not working

I've included the javascript by wp_enqueue_script('slider', plugins_url( 'slider.js', __FILE__ ) ); with just a simple $(document).ready(function () { alert("alert"); }); It shows up in the ...
0
votes
1answer
1k views

Trying to get fittext to work in Wordpress

I have the following code in my template page and I have registered jquery and fittext in my theme's functions.php. They are currently showing up in the footer as I set them to. I can set them up in ...
0
votes
1answer
177 views

Using jQuery .after inside loop

I have a bit of javascript that will dynamically add a static post to a loop. The script uses the jQuery 'after' method and on a static page it works beautifully but when inside the loop I don't get ...
10
votes
4answers
3k views

Solutions for generating dynamic javascript / CSS

Let's say you need to generate javascript or CSS code that depends on the current context. For example you have a form on the homepage that fires an ajax request on submit, and a different form on ...
8
votes
8answers
13k views

What does l10n.js do in WordPress 3.1? And how do I remove it?

I just installed WP 3.1 Beta 2 on my test server. I noticed that it ships with a new l10n.js file that gets automatically inserted into the header. I did a bit of digging and it has something to do ...
3
votes
1answer
2k views

How to replace regular jquery calls with CDN calls from Google?

I will like to implement a few of the boilerplate template features in one of my instance WordPress. I am trying to figure out how to exchange the regular jquery calls below <script ...
5
votes
2answers
2k views

Add custom shortcode button to Editor

Before the new version of Wordpress 3.0 came out I was using this jQuery code below to add custom buttons for my own shortcodes to the editor toolbar in the admin panel, it worked great. However with ...
1
vote
1answer
991 views

Create Image Uploader for Widget

I found this post// Use Media upload in custom widget on wordpress 3.5 I'm not experienced in any of this so I pretty much just copied the code he provided into my own functions.php file. I uploaded ...
7
votes
1answer
3k views

wp_enqueue_scripts, wp_register_scripts, wp_print_scripts: i'm confused

I've been reading up a bit on this subject, but the more I read - the more confused I get. Can someone explain to me in short what's the exact difference between wp_enqueue_scripts, ...
1
vote
1answer
430 views

Limit the Excerpt field in WP-Admin in words

Is it possible to limit the Excerpt field on the post page in words? Note that I am aware that it's possible to echo the excerpt and limit it in words, but I want the field itself to limit the amount ...
2
votes
1answer
445 views

WP_enqueue_script inside shortcode?

I've got shortcode that needs to include JS library only once and only there where it's used. function shortcode_function($atts, $content = null) { $class = shortcode_atts( array('something' ...
2
votes
1answer
289 views

Want to have the Post editor remembering the last editing position

As you probably know the WordPress theme editor remembers its last editing position, but I want my post editor to do the same (it jumps to the top if you save a post/page).... Any tips/hacks how to ...
2
votes
5answers
6k views

Adding onload to body

I'm currently trying to develop a plugin that will embed a Google Earth Tour into a WP post / page via a shortcode. The issue I am running into is that for the tour to load, I have to add an ...
1
vote
1answer
88 views

Customizer: When to use customize_preview_init VS customize_controls_enqueue_scripts

There appears to be some conflicts between the codex and the twentyfourteen theme code with respect to which action to hook to load your live preview .js (ex: customizer.js) In the twentyfourteen ...
1
vote
1answer
848 views

simple expandable vertical menu, java script problem

I am trying to create a simple expandable menu in wordpress. Bellow you can see the javascript I am using (copy and mix from internet). <script type="text/javascript"> ...
0
votes
3answers
231 views

Unable to run jQuery script in my template file

I really want to run a simple code in my template file. E.g. if I put somethign like this in my page.php: <script type="text/javascript"> jQuery(document).ready(function($) { ...
0
votes
2answers
230 views

My jQuery is enqueued properly. So why isn't it working?

I'm just trying to add a simple bit of Show/Hide jQuery to a child theme. $(document).ready(function(){ $("#openbtn").click(function(){ $("#openingtimes").toggle(300); }); }); I've saved the ...
5
votes
2answers
1k views

How to provide translations for a WordPress TinyMCE plugin?

I know that I can get my translations into JavaScript doing: $MyTranslations = array( 'translation1' => __("Some String 1", "MyTranslations"), 'translation2' => __("Some ...
3
votes
1answer
130 views

How to intercept already localized scripts

If a plugin uses some script (prominent example: jQuery UI Datepicker), but you're not happy with how the script renders the output, then there're two possibilities: 1. Unregister the script > Add ...
3
votes
2answers
361 views

Block metabox - No expanding, no moving around

I would like to make metaboxes as fixed elements, removing the expand function and the drag-and-drop function. Any ideas?
3
votes
4answers
3k views

How to handle multiple instance of “send_to_editor” js function

Here is what I am doing: I Added wordpress media upload with iframe popup when a button or link clicked. And with click of insert into post the image url placed on a textbox. send_to_editor() ...
3
votes
2answers
688 views

Admin Bar menu item that executes Javascript but does not reload the page?

I added a menu item to the Admin Bar that executes some Javascript to show debug information. The problem is that clicking this item also reloads the page. How can I prevent this? I was trying to ...
2
votes
1answer
464 views

How do I enqueue(or delay loading of) <script> tags in individual page posts?

My customer has many pages with <script> elements including javascript. <script src="myscriptforthispageonly.js"></script> I'm trying to get all scripts to load in the footer ...
2
votes
2answers
544 views

How to control contextual help section by code?

I had added some content to contextual help section for plugin options page. Now I'd like that page defaulted/toggled to contextual help section open on specific condition in my PHP code. My only ...
1
vote
1answer
178 views

How to get a jQuery script to run on a page?

I am having a hard time figuring out how to get a jQuery script to run on a Wordpress page of mine the "correct" way. I have followed this article and implemented what the first answer says to do. ...
1
vote
2answers
79 views

WordPress Displaying Thumbnails Vertically

WordPress is displaying my thumbnails vertically and VERY LARGE. Specifically it's displaying WooCommerce product page thumbnails vertically and VERY LARGE. Can't seem to figure out why or what piece ...