Help with enqueing scripts in footer after init action

If you enqueue the script to the footer while the page is being rendered (after the “wp_head” hook), you will have to manually add wp_print_scripts (or wp_print_footer_scripts) to the wp_footer action, like this: wp_enqueue_script( ‘jquery-gallery’, null, array( ‘jquery’ ), null, true ); add_action( ‘wp_footer’, create_function( ”, ‘wp_print_scripts( “jquery-gallery” );’ ) );

Performance-wise, is it better to enqueue a (small) script on every page or test to see if it’s needed?

What happens on the user’s side is off topic as @bungeshea said already. Once the user has loaded the file it will stay in the browser cache for a while, so you don’t have to worry about double loaded files anyway. But let’s look at the server side and how WordPress handles this. If you … Read more

Register script/style: Is it possible to customize the version query string via plugin?

Old answer (based on misconception that you wanted a cache buster): You can use add_query_arg() which adds/replaces query arguments. <?php /** * Plugin Name: wpse_84670 * Version: 0.0.1 * Description: replace script/style version with time as a cache buster */ /** * replace script or stylesheet version with current time * @param string $url the … Read more

wp_enqueue_script with dependencies doesn’t work

This is a bug in WordPress. https://core.trac.wordpress.org/ticket/35873 As far as I can see, it can currently be fixed with https://core.trac.wordpress.org/attachment/ticket/35873/35873.3.patch, if you are reading this some time later, it has probably already been fixed for your WordPress version. As a temporary workaround, set parent dependencies to both child and grandchild. This way grandchild.js will not … Read more

Select2 in WordPress

It’s not. They may have been planning it for 4.1 or 4.2, as suggested in your link, but for whatever reason it never happened. You can see a list of core-registered scripts that you include here. Another thing to keep in mind is that many (arguably too many) plugins enqueue their own version of the … Read more

Enqueue script with url_query variables?

I can’t get super specific without a more-detailed example from you, but I think you could combine get_query_var() and wp_enqueue_script() to do what you want like this: add_action( ‘wp_enqueue_scripts’, ‘sg_scripts’ ); function sg_scripts() { $current_slug = get_query_var( ‘page_name’ ); wp_enqueue_script( ‘sg_custom_js’, get_template_directory_uri() . ‘/js/somefile.php?slug=’ . $current_slug, $dependencies, $version, $in_footer); } (I left the last three … Read more

Enqueueing Scripts on a Custom Top-level Menu Page

You could try replacing if( ‘nonpareil_theme_options’ != $hook ) with if( ‘toplevel_page_nonpareil_theme_options’ != $hook ) if you have the custom menu added like this: add_action(‘admin_menu’, ‘register_custom_menu_page’); function register_custom_menu_page() { add_menu_page(‘Nonpareil options’,’Nonpareil options’, ‘administrator’, ‘nonpareil_theme_options’, ‘nonpareil_theme_display’ ); } Edit: It looks like you are using this admin_enqueue_scripts example in the Codex: http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts#Example:_Target_a_Specific_Admin_Page so in your case … Read more

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