Enqueue script only when shortcode is used, with WP Plugin Boilerplate

Why it’s not working: You need to use the wp_enqueue_scripts action hook. You’ve used wp_register_script as an action hook, however, there is no action hook named wp_register_script in WordPress core. If this was just a silly mistake, then you already have the answer. Read on if you need more information regarding the topic: Attaching a … Read more

Enqueue Script with data attributes

Please try code given below: function add_data_attribute($tag, $handle) { if ( ‘chargebee’ !== $handle ) return $tag; return str_replace( ‘ src’, ‘ data-cb-site=”mydomainame” src’, $tag ); } add_filter(‘script_loader_tag’, ‘add_data_attribute’, 10, 2);

Why is jquery-ui-core enqueueing in my footer instead of the header?

Why do you need it in the header? It’s enqueuing in the footer because when it was registered it was set to enqueue in the footer. In wp-includes/script-loader.php: $scripts->add( ‘jquery-ui-core’, ‘/wp-includes/js/jquery/ui.core.js’, array(‘jquery’), ‘1.8.12’ ); $scripts->add_data( ‘jquery-ui-core’, ‘group’, 1 ); The second line forces it to load in the footer. You could deregister the script, then … Read more

jQuery in header or footer

There is a lot of leftovers in script-related articles in Codex that are not entirely correct (putting it mildly). The enqueue should not be done before wp_head(), it should be done on wp_enqueue_scripts. Which is technically early inside wp_head(). It doesn’t harm performance, because registering/enqueueing script is merely explaining to WordPress how it should be … Read more

Notice that the wp_enqueue_style is not being called correctly!

The problem is that the wp_enqueue_style() call is inside of the category_collapse() member function of the CategoryCollapse() class, and the CategoryCollapse() class is being instantiated by a callback hooked into the plugins_loaded action hook. That means that the wp_enqueue_style() function is attempting to execute at the plugins_loaded hook, which fires before init, wp_enqueue_scripts, and admin_enqueue_scripts. … Read more

The difference between calling wp_enqueue_scripts to load scripts and styles in custom theme

wp_enqueue_scripts Action Hook: WordPress provides various names (or place holders) that can be used to inject callback functions within WordPress core’s execution lifecycle. These are called action and filter hooks. wp_enqueue_scripts is a WordPress action hook. Note: It’s not wp_enqueue_script, it’s plural: wp_enqueue_scripts. With this hook, we add script or style on the correct time … Read more

How to en-queue bootstrap 4 to theme?

You can use action hook and enqueue script and style to the site. function my_scripts() { wp_enqueue_style(‘bootstrap4’, ‘https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css’); wp_enqueue_script( ‘boot1′,’https://code.jquery.com/jquery-3.3.1.slim.min.js’, array( ‘jquery’ ),”,true ); wp_enqueue_script( ‘boot2′,’https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js’, array( ‘jquery’ ),”,true ); wp_enqueue_script( ‘boot3′,’https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js’, array( ‘jquery’ ),”,true ); } add_action( ‘wp_enqueue_scripts’, ‘my_scripts’ ); If you want to add the scripts after jQuery then you can use the … Read more

How to echo JS right after enqueued script to put it into noConflict mode?

You have to filter script_loader_src, check if you are on the correct script and add a one-time filter for clean_url. Then add your extra script, and make sure the output is syntactically valid. Pretty simple, albeit rather hacky. class Extra_Script { private $extra = []; private $handle; private $url; private $versioned_url; public function __construct( $handle, … Read more

Get php var inside javascript file (making plugin)

You can use wp_localize_script() to pass php variables to javascript. You create an array in php and then pass it to the function as the third parameter. It will come through as an object you name with the second parameter. First, register the script. wp_register_script( ‘custom-name-js’, plugins_url( ‘assets/custom-js.php’, __FILE__ ) ); Second, build your array … Read more

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