Tag Info

New answers tagged

0

There are a few problems but the main one is when sidebarEffects.js is loaded the HTML it's looking for doesn't exist yet. So... var container = document.getElementById( 'st-container' ) // and buttons = Array.prototype.slice.call( document.querySelectorAll( '#st-trigger-effects > button' ) ) are both empty when the script is run. Easiest way to fix ...


0

For using require JS you need add in head <!-- Delayed execution of inline jQuery scripts with ready waiting event --> <script type="text/javascript">(function(w, d, u){w.readyQ = []; w.bindReadyQ = []; function p(x, y){if (x == "ready"){w.bindReadyQ.push(y); } else{w.readyQ.push(x); }}; var a = {ready:p, bind:p}; w.$ = w.jQuery = function(f){if ...


0

function enqueue_lazyload() { wp_enqueue_script('jquery_lazy_load', get_stylesheet_directory_uri() . '/js/jquery.lazyload.min.js', array('jquery'), '1.9.1'); } add_action('wp_enqueue_scripts', 'enqueue_lazyload'); Next, we have to add a small bit of Javascript to our footer to get the lazy load plugin to recognize images. You can see how this works on ...


3

I was curious about this and checked the Codex on keyboard shortcuts, but didn't find it mentioned there. I searched and found out that this seems to be already solved, e.g. here and here. I haven't tested out these other plugins so I'm not sure how they solve it, but I decided to take on the challenge and see how this could be solved ;-) So here's my ...


0

In the context of parent - child themes, be aware that: The get_template_directory_uri() will give you the parent theme directory uri: https://codex.wordpress.org/Function_Reference/get_template_directory_uri. The get_stylesheet_directory_uri() will give you the child theme directory uri: ...


0

You can achieve it by the following code. Open you header.php find the following text in that file < !DOCTYPE html> and replace it with the following. <?php /** @package WordPress @subpackage Default_Theme **/ header("Access-Control-Allow-Origin: *"); ?> <! DOCTYPE html> ... Now u can find Access-Control-Allow-Origin: * in ...


0

Oh okay.. I think I solved it. I put the script in the header.php (I think "into the loop" as they say?) just behind the opening <header>-tag: <body> <header> <script type="text/javascript"> (function($) { $(document).ready(function(){ $(window).scroll(function(){ ...


1

You are calling jQuery wrong by the shorthand $. If you will look in your console you will see an error that $ is not a function / undeclared etc (this is due to jQuery's conflict mode if I am not wrong). Your code should look something like this: <script type="text/javascript"> jQuery(function($) { $( "a.toggle").click(function() { ...


0

I think you are pretty much there. In your JavaScript you are referencing log_forms as a class, but in your HTML it looks like log_forms is an ID. So you would need: $( "a.toggle").click(function() { $("#log_forms").toggleClass( "open" ); }); Then the css would be: #log_forms{ display: none; } #log_forms.open{ display: block; } Example: ...


2

The script_loader_tag filter, added in version 4.1, addresses this issue. To add an async attribute to an enqueued script you can do: /** * Add an aysnc attribute to an enqueued script * * @param string $tag Tag for the enqueued script. * @param string $handle The script's registered handle. * @return string Script tag for the enqueued script */ ...


0

The get_option and update_option functions in PHP automatically handle serialization/unserialization for you: https://codex.wordpress.org/Function_Reference/get_option If you need to interface with these functions using JavaScript (assuming JavaScript and not Java, as others have pointed out) you could register an AJAX endpoint that calls these functions ...


1

The "Failed to load resource" is probably a red herring and isn't related to your issue. The fact that it is throwing an error about the $ shortcut means your js file is being loaded correctly. The likely issue is that jQuery in WordPress loads in "noConflict" mode. As such the $ shortcut will not work by default. Try replacing your script with this: ...


2

I'm not really sure why you'd want to do this...but the only thing I can think of that might work is something like this: function prefix_block_resources(){ if(is_admin())return; //I can't imagine any scenario where blocking scripts in the admin area would be wise. global $wp_scripts; global $wp_styles; ...


0

This works for me: tinyMCE.execCommand("mceAddEditor", false, id); tinyMCE.execCommand('mceAddControl', false, id);


0

First you need to do what Dougal said about getting the ajax-url right. I would also specify the dataType. dataType is the type of data that you're expecting back from the server, you can read more about it here. And I would use wordpress's get_template_part to get the template.


1

obviously the answer is no. wordpress do not load JS and CSS on the admin side if it is not needed. In addition your method will probably trigger all kinds of plugins which assume that wp_head and wp_footer are triggered only at the frontend which might create "interesting" side effects. If you want to customize the admin you will have to actually write ...


1

So, you're using wp_localize_script to inject the ajax url. But you didn't use the localized var handle to access that value. Try this: /* ... */ $.ajax({ url: ajaxStuff.ajaxurl, // NOTE use of 'ajaxStuff' object /* ... */


0

Here is some generic js you could use to accomplish this. This code is intentionally generic, so you will need to make it work for your scenario. You can load up your various states and hide them with the 'js-display-toggle' class. When the appropriate country is chosen from 'base' select menu, then you remove the toggle class and show those state. ...


0

First off, jquery is most likely already enqueued by the main theme. But if not, the proper way is to call wp_enqueue_script('jquery') in a function for the action hook wp_enqueue_scripts. Example: function enqueue_jquery() { wp_enqueue_script('jquery'); } add_action('wp_enqueue_scripts', 'enqueue_jquery'). This code would need to be added to the ...


1

I actually ran into a similar issue yesterday. A theme I was working with was adding 500+ lines of internal styles to the header which absolutely drives me nuts! I ended up finding a clever solution online to work around this which you could use for CSS. The JavaScript side I'll explain toward the bottom. --- :: CSS :: --- There's a few key points in how ...


-1

You've probably came across several different methods for including JavaScript and CSS. There is one primary method recommended in the WordPress Codex. The safe and recommended method of adding JavaScript to a WordPress generated page, and WordPress Theme or Plugin, is by using wp_enqueue_script(). This function includes the script if it hasn't already ...


0

Use wp_enqueue_script() with $in_footer parameter set to true, when loading scripts with your shortcode. To pass data from the PHP part of your code to the JS part use wp_localize_script(). wp_enqueue_script( 'script_name', '/script-location/script.js', array(), '1.0.0', true ); $data_array = array( 'key_1' => 'val_1', 'key_2' => 'val_2' ); ...


1

Building on the accepted answer and filling in some details... You need to call wp_localize script right after wp_enqueue_script. So, something like this: function my_enqueue_scripts() { wp_enqueue_script( 'myjs', plugins_url( 'js/my.js', __FILE__) ); $options = get_option( 'my_settings' ); $scriptData = array( ...



Top 50 recent answers are included