Tag Info

New answers tagged

2

You can set the priority in hook. Priority is the 3rd parameter in the hook. In the following example, wp_enqueue_scripts will have priority of 99 which is higher than normal priority. Default priority is 10. So it will load at last function load_last_style() { wp_enqueue_style( 'style-name', get_stylesheet_uri() ); } add_action( 'wp_enqueue_scripts', ...


1

Scripts should be enqueued on wp_enqueue_scripts action hook, which runs after init action. So dequeuing on init won't work because sripts are not enqueued yet. Before enqueued scripts are printed, wp_print_scripts action is triggered so you can dequeue or unregister scripts safely at this moment: add_action( 'wp_print_scripts', 'drw_timelinr_dequeue' ); ...


0

If loadScripts() is registered/enqueued correctly (the code posted doesn't show the hook used) then is it enqueued on wp_enqueue_scripts which runs well after init so what you are doing is trying to remove something that hasn't been added yet, and will be added later. Assuming that: add_action('wp_enqueue_scripts', 'drw_timeline_js', PHP_INT_MAX); ...


0

Found a solution here. Just add this js code: var makeTabs = function(selector) { $( selector ) .find( "ul a" ).each( function() { var href = $( this ).attr( "href" ), newHref = window.location.protocol + '//' + window.location.hostname + window.location.pathname + href; if ( ...


-1

As toscho pointed out, use jQuery(document).ready(function($) { ... }); instead of $( function() { ... }); Edit: Main problem is WP rich text editor escaping your html <script> tags. See https://codex.wordpress.org/Using_Javascript at the bottom of the page for a plugin-based workaround to turn off formating for specific posts/pages, allowing you to ...


1

There's a much better and more reliable way than naming your plugin "ZZ" - use a delayed hook on plugins_loaded, which fires after all plugins are loaded: function wpse_191178_plugins_loaded() { // Do your stuff } add_action( 'plugins_loaded', 'wpse_191178_plugins_loaded', 100 );


0

Since plugins are loaded by the alphabetical order of plugin's folder name (not by plugin's name), name your plugin folder ZZ.. and it should load last :-)


1

You gave each each script the same handle/id of 'grid' Try something like this. function banana_scripts() { wp_enqueue_script('grid', get_stylesheet_directory_uri() . '/js/jquery.min.js', null, null); wp_enqueue_script('grid2', get_stylesheet_directory_uri() . '/js/main.js', null, null); } add_action('wp_enqueue_scripts', ...


0

JS variables are not directly replaced as you are expecting. Localizing in your code is correct. When you do var jsonPath = itajax.ajaxurl;, value of itajax.ajaxurl is assigned to the variable jsonPath. If you debug this variable in the console, you will get the correct value. console.log(jsonPath);


0

You should be able to dequeue like normal. Despite the complexity of the function, it is really just enqueueing scripts and styles. Tested with the admin bar script on the front end: add_action( 'wp_enqueue_scripts', function() { wp_dequeue_script('admin-bar'); } ); You just want admin_enqueue_scripts and set-post-thumbnail: add_action( ...


1

All scripts and styles which get included by either wp_enqueue_script() or wp_enqueue_style() get displayed in the action hook wp_head or wp_footer. So the proper moment to merge them together would be there. Hook in very early and do your magic there. The wp_enqueue_styles hook is not necessarily the best one, since it is not always the hook where the ...


1

Sounds to me like what you want to do, is create a standalone plugin for this. You've already got a lot of the ground work setup (Eg the code) it would just be a matter of creating the plugin and dropping all your code into this. You can even change retain your html template and just call it via a shortcode. Then you can retain your markup, and also use the ...


0

for opening thickbox where you design custom fields look and feel login box wp_enqueue_style('thickbox'); wp_enqueue_script('thickbox'); wp_enqueue_style('login'); <input class="button button-primary button-large open" type="button" value="Add" name="Addmanager"> <script type="text/javascript"> $('.open').click(function(event) { ...


0

I found an other way that works well for me: When initializing the plugin, do not enqueue your scripts and styles, but register them with wp_register_style and wp_register_script. Next you can load the script/style on demand. For example when you render a shortcode with wp_enqueue_style("your_style") and wp_enqueue_script("your_script"). This way the ...


1

As Rarst already noted, you answered your question. You are telling the software to load those scripts all the time. You need to control that process. Software is stupid. It can't decide when a good time is to load the code. SO... Since the plugin should only run when one of its shortcodes are called, ... Since you say the script should load only ...


0

You are answering your own question — scripts are being enqueued because that's what plugin does every load unconditionally. There is no logic that controls when should it happen or not happen, it simply happens always. If you take a closer look at a plugin that does it more intelligently you will usually notice one of these things: there are conditional ...


1

There is no action called wp_enqueue_script, it's wp_enqueue_scripts, plural, and both scripts and styles should be enqueued on that action.


0

You can use init action to set cookie, and other init action to read it. However due its a cookie... you will need also to check GET variable. add_action('init', 'is_it_mobile_or_desktop', 1); function is_it_mobile_or_desktop(){ if (isset($_GET['site']) && in_array($_GET['site'], array('mobile', 'desktop')) ) { setcookie( 'site', ...



Top 50 recent answers are included