Enqueue script on specific WooCommerce template

You need to delay the firing of your code, otherwise your conditionals will evaluate false (the request won’t have been parsed yet). Use the action wp_enqueue_scripts: function wpse_182357_enqueue_scripts() { // Your code } add_action( ‘wp_enqueue_scripts’, ‘wpse_182357_enqueue_scripts’ ); Update: Missed the root of the problem – is_page_template() only works for pages. Rather than checking if the … Read more

Enqueue jQuery in WordPress

You’re on the right track, but missing one piece: add_action(‘wp_enqueue_scripts’, ‘my_scripts_method’); add_action allows you to run code at specific times during page loads / specific events. The above action tells WP to run your function when it is adding the scripts to the html head element. Your function in turn instructs WP to add the … Read more

Javascript not included

You’re mixing up the singular wp_enqueue_script, which adds a script, with the plural wp_enqueue_scripts which is an action and a function that triggers that action. I think you want function theme_scripts() { wp_enqueue_script( ‘custom-script’, get_template_directory_uri() . ‘/js/menu-fix.js’, array(‘jquery’), ‘1.0’, true); } add_action(‘wp_enqueue_scripts’, ‘theme_scripts’); i.e. register against the enqueue_scripts-plural action that calls enqueue_script-singular.

enqueue script on custom post type archive page

You can save your time and server load by not using wp_register_script and wp_register_style when you don’t need them definitely. wp_enqueue_style and wp_enqueue_script do the same job themselves when not involving excessive functions. Here is easier and more readable code up to date with the accepted answer by @vancoder: <?php function opby_theme() { wp_enqueue_script( ‘responsive-img’, … Read more

How wp_enqueue_script works?

In simple case you need to enqueue script before header scripts are printed, which happens in wp_head hook. Basic approach would be this in functions.php of your theme: add_action(‘wp_enqueue_scripts’, ‘my_enqueue_scripts’); function my_enqueue_scripts() { wp_enqueue_script(‘jquery’); }

Add extra parameter in tag using script_loader_tag

You can use script_loader_tag filter to fulfill your requirement. add below code in your active theme’s functions.php file. it will add extra parameter in your script tag. function add_attribute_to_script_tag($tag, $handle) { # add script handles to the array below $scripts_to_defer = array(‘wpfrank-ptbw-pinit-js’); foreach($scripts_to_defer as $defer_script) { if ($defer_script === $handle) { return str_replace(‘ src’, ‘ … Read more

Add last modified time as version to css and js

You could use add_query_arg() but then you’d have to parse the uri everytime, I’d rather create a wrapper function for wp_enqueue_script/style: function my_enqueuer($my_handle, $relpath, $type=”script”, $my_deps=array()) { $uri = get_theme_file_uri($relpath); $vsn = filemtime(get_theme_file_path($relpath)); if($type == ‘script’) wp_enqueue_script($my_handle, $uri, $my_deps, $vsn); else if($type == ‘style’) wp_enqueue_style($my_handle, $uri, $my_deps, $vsn); } Add this in your functions file … Read more

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