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

Your question is a bit broad. We actually have a one question per post policy. I’m going to try to answer though My first question is, shouldn’t most themes that you download out there automatically include jQuery in your header anyway? Well, basically correct. So many features today in a theme needs jquery to run … Read more

Is it possible to change the attributes of a registered style or script before it fires?

Modify a registered style’s path I wanted to tweak the path to one of the WordPress admin stylesheets so i could keep requests down, and because it makes little sense to include two stylesheets, when the one i’m calling redefines all the styling in the stylesheet enqueued by WordPress. The idea is basically to re-point … Read more

How to prevent wordpress from loading old versions of jquery in wp_head();?

add_action(‘wp_enqueue_scripts’, ‘no_more_jquery’); function no_more_jquery(){ wp_deregister_script(‘jquery’); } That will deregister jquery. But why wouldn’t you want jQuery at all? If you mean to simply use your own, you should do it in that function, like this: add_action(‘wp_enqueue_scripts’, ‘no_more_jquery’); function no_more_jquery(){ wp_deregister_script(‘jquery’); wp_register_script(‘jquery’, “http” . ($_SERVER[‘SERVER_PORT’] == 443 ? “s” : “”) . “://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js”, false, null); wp_enqueue_script(‘jquery’); … Read more

Get list of scripts / styles and show file which enqueued them

This is not possible the way you think. It would maybe be possible if you use Reflections or debug_backtrace(), but there’s no reliable way to do this. WordPress does not keep a stack or queue where it tracks file names. The only thing I could imagine is just hooking into the action and inside wp_enqueue_scripts(): … Read more

Load plugin scripts and styles only on plugin page

When you register a plugin option page you get a hook from the registration function: $hook = add_menu_page( ‘T5 Demo’, // page title ‘T5 Demo’, // menu title ‘manage_options’, // capability ‘t5-demo’, // menu slug ‘my_render_page’ // callback function ); Use this hook to enqueue the scripts and styles: add_action( “admin_print_styles-$hook”, “my_enqueue_style” ); add_action( “admin_print_scripts-$hook”, … Read more

Add a script as a dependency to a registered script

Digging through https://github.com/WordPress/WordPress/blob/3.5.1/wp-includes/class.wp-dependencies.php all registered scripts are stored in the global $wp_scripts. You can access them directly through that, but I prefer to use the API when it exists. In this case, $wp_scripts->query() returns a particular registered script (a _WP_Dependency object – see source). A _WP_Dependency object stores the dependencies as an array of handles, … Read more

Correct Method to run scripts with dependencies without enqueue?

function script_that_requires_jquery() { wp_register_script( ‘script-with-dependency’, ‘http://www.example.com/script-with-dependency.js’, array( ‘jquery’ ), ‘1.0.0’, true ); wp_enqueue_script( ‘script-with-dependency’ ); } add_action( ‘wp_enqueue_scripts’, ‘script_that_requires_jquery’ ); This is the correct method to enqueue scripts (and styles for that matter). You should always be using wp_enqueue_scripts to hook scripts and styles to. There are a few thing here to check when you … Read more

How can I create a bash install script for my WordPress sites setup (WP+plugins+theme)?

To always get latest plugin take for example my plugin: http://wordpress.org/extend/plugins/wordpress-file-monitor-plus/ the download link for the latest is: http://downloads.wordpress.org/plugin/wordpress-file-monitor-plus.1.1.zip but if you remove the version from the download link you always get the latest version: http://downloads.wordpress.org/plugin/wordpress-file-monitor-plus.zip EDIT: Have you considered keeping a folder of the latest wordpress and plugins unpacked? Then as soon as a … Read more