enqueue_scripts() in child theme doesn’t work

Technically, your problem (as already pointed out) is that you are using a function that echos instead of returns your path. However, the use of bloginfo/get_bloginfo to retrieve theme directory paths is long since discouraged. ‘stylesheet_url’ – Displays the primary CSS (usually style.css) file URL of the active theme. Consider echoing get_stylesheet_uri() instead. ‘stylesheet_directory’ – … Read more

add jquery file if a certain page is included

While you can approach it with “what template is loaded”, WP isn’t engineered for such logic. Template load is result of logic processing, not the other way around. You should check out Conditional Tags and determine which logical check applies to your situation. Other than that you should be: running script-related logic on appropriate wp_enqueue_scripts … Read more

Wp_deregister_script() doesn’t work

Paste it into your themes functions.php As you have said that you are working on a child theme, then paste this code into your child themes functions.php add_action( ‘wp_print_scripts’, ‘deq_der_script’, 100 ); function deq_der_script() { wp_dequeue_script( ‘quovolver’ ); wp_deregister_script( ‘quovolver’ ); }

Incorrect filenames in load-scripts.php parameters

Do you have the “all-in-one-wp-security-and-firewall” plugin? More info: https://wordpress.org/support/topic/load-scriptphp-fails-to-load?replies=3 Short answer, if so, disable the “Deny Bad Query Strings” option. If not, check for any other “security” plugins you have that might be doing dumb things.

Remove pretty photo style and script if not exist!

I got it to working finally .. The code is: add_action( ‘wp_enqueue_scripts’, ‘pretty_photo_styles’, 100 ); function pretty_photo_styles() { if ( ! is_single() ) { wp_dequeue_script( ‘pretty_photo’ ); wp_dequeue_style( ‘pretty_photo’ ); } } Please someone correct it if I missed anything! I tried it and it worked for me.

Using WP functions inside javascript

I found out about wp_localize_scripts here and it solves my issue: functions.php $var=get_current_user_id(); $params = array( ‘max’ => $var ); wp_localize_script( ‘myscript’, ‘MyScriptParams’, $params ); wp_enqueue_script(‘myscript’); and in the .js file I can retrieve this variable with MyScriptParams.max.

Call two different function.js depending on page

You can write conditionals in your functions.php file to conditionally load the javascript files. For example: function theme_scripts() { // If this is the home page, run this script if(is_home()) { wp_enqueue_script( ‘example-script’, get_stylesheet_directory_uri().’/path/to/file.js’); } // Otherwise, run this script else { wp_enqueue_script( ‘other-script’, get_stylesheet_directory_uri().’/path/to/file.js’); } } add_action( ‘wp_enqueue_scripts’, ‘theme_scripts’ ); Codex page for home … Read more