How do I enqueue a JavaScript in my footer via the functions.php file?

First, create a static js file with those inline codes.. !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0]; if(!d.getElementById(id)){js=d.createElement(s);js.id=id; js.src=”https://platform.twitter.com/widgets.js”; fjs.parentNode.insertBefore(js,fjs);} }(document,”script”,”twitter-wjs”); var options = { “url”: “/my-styles.css” }; CustomizeTwitterWidget(options); Then enqueue it at footer as the dependent of twitter-customize script which you already enqueued. function my_footer_enqueue() { wp_register_script( ‘twitter-customize’, get_template_directory_uri() . ‘/js/customize-twitter-1.1.min.js’, array(), ‘1.0’, true ); wp_enqueue_script( ‘twitter-customize’ ); wp_enqueue_script( … Read more

How to cancel `wp_print_scripts`?

There is a way, but it’s not recommended since there might be some other inline scripts attached to the enqueued scripts. You can hook to the wp_enqueue_scripts action and empty the global $wp_scripts as follows: add_action( ‘wp_enqueue_scripts’, ‘remove_all_scripts’, 1000 ); function remove_all_scripts() { global $wp_scripts; $wp_scripts->queue = array(); } You can then run a loop … Read more

How to enqueue a style using wp_enqueue_scripts()?

The second parameter of wp_enqueue_style() is an optional path.You are passing an empty array, which will enqueue nothing. get_template_directory_uri() retrieves the current theme’s root URI, which you can use in wp_enqueue_style(): add_action(‘wp_enqueue_scripts’,’homepage’); function homepage(){ if ( is_page_template(‘page-home.php’) ) { wp_enqueue_style(‘home-css’, get_template_directory_uri() . ‘/css/flags.min.css’, ‘1.0.0’, true ); } } I mentioned “Optional”, since there is also … Read more

Modernizr check first, then move on to wp_register_script()/wp_enqueue_script

Please check the example of Alex Hempton-Smith, maybe its help you. <?php function urls_of_enqueued_scrips( $handles = array() ) { global $wp_scripts, $wp_styles; foreach ( $wp_scripts->registered as $registered ) $script_urls[ $registered->handle ] = $registered->src; foreach ( $wp_styles->registered as $registered ) $style_urls[ $registered->handle ] = $registered->src; if ( empty( $handles ) ) { $handles = array_merge( $wp_scripts->queue, … Read more

Which jQueryUI handles are predefined in wordpress?

Just take a look at the Codex for all the default scripts and their slugs. The jQuery UI stuff is: Name Handle Dependencies jQuery UI Core jquery-ui-core jquery jQuery UI Widget jquery-ui-widget jquery jQuery UI Mouse jquery-ui-mouse jquery jQuery UI Accordion jquery-ui-accordion jquery jQuery UI Autocomplete jquery-ui-autocomplete jquery jQuery UI Slider jquery-ui-slider jquery jQuery UI … Read more

How do I enqueue a js file in functions.php for a if lt IE 9 statement? [duplicate]

You can do it in two ways…. Solution One: <?php add_action( ‘wp_head’, ‘myscript’ ); function myscript(){ echo ‘<!–[if lt IE 9]><script src=”https://wordpress.stackexchange.com/questions/138051/your_js_file_path”></script><![endif]–>’; }; ?> Solution Two: <?php global $wp_scripts; wp_register_script( ‘jsFileIdentifier’, ‘YourJsFilePath’, array(), ‘3.6.2’ ); $wp_scripts->add_data( ‘jsFileIdentifier’, ‘conditional’, ‘lt IE 9’ ); ?>

Notice: wp_enqueue_script was called incorrectly

You do not show how you hook your wp_enqueue_script() call. But the error message you get is pretty clear, use one of the following hooks: wp_enqueue_scripts admin_enqueue_scripts login_enqueue_scripts depending on the use case – see the notes at the wp_enqueue_script() codex page for additional information. For example do for correctly enqueuing on the frontend: function … Read more

Optimizing WordPress’s styles and scripts

Query Monitor will show you what is loaded or you can print them directly. function print_wp_scripts_queue(){ $scripts = wp_scripts(); echo “<pre><h1>scripts</h1>”; print_r ( $scripts->queue ); echo “<h1>todo</h1>”; print_r ( $scripts->to_do ); echo “<h1>done</h1>”; print_r ( $scripts->done ); echo “<h1>registered</h1>”; print_r ( $scripts->registered ); echo “</pre>”; wp_die(); } add_action( ‘wp_head’, ‘print_wp_scripts_queue’, PHP_INT_MAX ); wp_deregister_script removes a … Read more

What are the advantages of using wp_enqueue_script()

How about API? Let’s Check this example. $id = ‘plugin-id’; $syffix = ( ( defined( ‘SCRIPT_DEBUG’ ) && SCRIPT_DEBUG ) ? ” : ‘.min’ ); $script_url = plugins_url( ‘js/’ .$id . $suffix . ‘.js’, __FILE__ ); $dependencies = array( ‘jquery’, ‘underscore’ ); wp_register_script( $id, $script_url, $dependencies, $version, true ); wp_localize_script( $id, ‘pluginJSL10nData’, array( ‘home’ => … Read more

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