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

WP_Scripts and WP_Styles classes are behind wp_enqueue_script and wp_enqueue_style functions. If you take a look at classes implementation (scripts and styles) then you will see that WP_Scripts class doesn’t support any kind of conditional scripts, but! you can see that WP_Styles does! The problem is that wp_enqueue_style doesn’t allow you to setup condition. So we … Read more

Is there a JavaScript API? How to access public and private data in JS?

TL;DR There is no JavaScript API in the WordPress core and no one is planned, but actually, there is no need of it. Backend First of all let’s say that, regarding the backend, some useful information can be fetched from already present JavaScript global variables (WordPress loves all global flavors). E.g. ajaxurl for the admin-ajax.php … Read more

Using get_option() in JavaScript

Define an array of parameters to be injected into the script: $script_params = array( ‘myWidth’ => get_option(‘my_width’) ); Localize the script via wp_localize_script: wp_localize_script( ‘your-script-handle’, ‘scriptParams’, $script_params ); scriptParams now is a js object you can access from within the script: alert( scriptParams.myWidth ); // the value from the PHP get_option call in the js

wp_enqueue_scripts, wp_register_scripts, wp_print_scripts: i’m confused

wp_print_scripts is the action that runs when scripts are output to the template. wp_register_script and wp_enqueue_script are functions for registering/enqueueing scripts to be output when wp_print_scripts runs. you can’t register or enqueue styles in the wp_print_scripts action hook because styles have already been output in the wp_print_styles hook, which runs before wp_print_scripts. refer to the … Read more

force enqueue script to be first in order of prominence

You just need to enqueue your scripts before plugin does it. You can do it by setting priority to 0 for your hook. For example, do the following: add_filter( ‘wp_enqueue_scripts’, ‘wpse8170_enqueue_my_scripts’, 0 ); // or if you enqueue your scripts on init action // add_action( ‘init’, ‘wpse8170_enqueue_my_scripts’, 0 ); function wpse8170_enqueue_my_scripts() { wp_enqueue_script( ‘myscript’, ‘http://path/to/my/script.js’, … Read more

How to enqueue script if widget is displayed on page?

You should be able to call wp_enqueue_script() as part of your Widget output. Edit Quick-and-dirty, using the bare-bones Widgets API class example: <?php class wpse48337_Widget extends WP_Widget { public function __construct() { // widget actual processes } public function form( $instance ) { // outputs the options form on admin } public function update( $new_instance, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)