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: http://core.trac.wordpress.org/browser/tags/3.0.4/wp-admin/load-styles.php I was wondering if it’s possible to use them in the front-end too, not just admin, because they can concatenate all enqueued scripts, and serve them as a single gzipped file 4 late answer From a brief look: You’d have … Read more

Is it possible to use wp_localize_script to create global JS variables without a specific script handle?

Can we somehow use wp_localize_script() to create global js variables without a specific script handle which can be accessed from all the js files, even if the js scripts are not enqueued properly by using wp_enqueue_script ? This is the code I am using which creates varibale for ‘ajaxscript’ handle, so I cant access the … Read more

How to add a javascript snippet to the footer that requires jQuery

I know I can add a script file to the footer of wordpress that requires jquery using this code: <?php function my_scripts_method() { // register your script location, dependencies and version wp_register_script(‘custom_script’, get_template_directory_uri() . ‘/js/custom_script.js’, array(‘jquery’), ‘1.0’, true); // enqueue the script wp_enqueue_script(‘custom_script’); } add_action(‘wp_enqueue_scripts’, ‘my_scripts_method’); ?> But what if I want to add just … Read more

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. add_action( ‘wp_enqueue_scripts’, ‘wpcf7_enqueue_scripts’ ); function wpcf7_enqueue_scripts() { // jquery.form.js originally bundled with WordPress is out of date and deprecated // so we … Read more

wp enqueue style on specific page templates

I am in the process of a theme, I would like to add landing pages using page-templates. I cannot find anywhere that shows how to enqueue style or js for specific page templates. Any suggestions. Ex. Landing Page 1 – landing-page-template-one.php will need very different style and js than the blog or homepage. 6 If … Read more

Check if a script/style was enqueued/registered

Is it possible to test whether a script or a style was registered using wp_register_script/_style or wp_enqueue_script/_style? All functions doesn’t return a value and I’m completely clueless. I need it to switch between different functions depending on stylesheet-libraries and scripts I offer. Thank you! 2 There is a function called wp_script_is( $handle, $list ). $list … Read more

Enqueue core jQuery in the footer?

I have this in my functions.php file and I can’t get jQuery to load in the footer. The includes file loads in the footer fine, though. What else do I need to do? function starter_scripts() { wp_enqueue_style( ‘starter-style’, get_stylesheet_uri() ); wp_enqueue_script( ‘jquery’, ”, ”, ”, true ); wp_enqueue_script( ‘includes’, get_template_directory_uri() . ‘/js/min/includes.min.js’, ”, ”, true … Read more

ajaxurl not defined on front end

I am trying to create a ajaxform on the front side. I am using the code jQuery.ajax( { type: “post”, dataType: “json”, url: ajaxurl, data: formData, success: function(msg){ console.log(msg); } }); for which I am getting error Uncaught ReferenceError: ajaxurl is not definedworklorAjaxBookForm @ ?page_id=2:291onclick @ ?page_id=2:202 While using similar code on the admin backend … Read more

How do I dequeue a parent theme’s CSS file?

My parent theme (Starkers) adds a CSS file that I’m trying to remove (I want to use @import instead so I can override styles more easily). Starkers has the following in its functions.php: add_action( ‘wp_enqueue_scripts’, ‘script_enqueuer’ ); function script_enqueuer() { wp_register_script( ‘site’, get_template_directory_uri().’/js/site.js’, array( ‘jquery’ ) ); wp_enqueue_script( ‘site’ ); wp_register_style( ‘screen’, get_template_directory_uri().’/style.css’, ”, ”, … Read more