Enqueue Script with URL parameters

WordPress can automatically add the query variables for you. Instead of directly writing the query arguments, you can use it this way: $args = array( ‘f’ => ‘j’, ‘s’ => ‘w’, ‘c’ => ‘t’ ); wp_enqueue_script( ‘param-example’, add_query_arg( $args, ‘https://domain.com/example’) ); This is your solution, since according to code reference, the return value is unescaped … Read more

Conditionally dequeue dependency of scripts

Solution 1: Here we will dequeue and deregister elementor-dialog and elementor-frontend, then we will re-register elementor-frontend without the elementor-dialog dependency: // This needs to fire after priority 5 which is where Elementor // handles enqueueing scripts. We’re ok since the default is 10. add_action( ‘wp_enqueue_scripts’, ‘wpse_elementor_frontend_scripts’ ); function wpse_elementor_frontend_scripts() { // Optionally add guard clauses … Read more

Issue with using Underscore in WordPress

You need to set it as a dependency for your script, this is the best way you can make sure, Underscore.js is loaded before your script (which means, the methods will be available). function loadAdminScripts() { wp_register_style( ‘admin-style’, plugins_url(‘admin-style.css’, __FILE__) ); wp_register_script( ‘pluginAdminPage’, plugins_url(‘pluginAdminPage.js’, __FILE__), [ ‘jquery’, ‘underscore’, ] ); wp_enqueue_style(‘admin-style’); wp_enqueue_script(‘pluginAdminPage’); } add_action(‘admin_enqueue_scripts’, ‘loadAdminScripts’); … Read more

enqueue and localize script in footer

You should be setting it to show in the footer with the register, so your code should look like this: wp_register_script( ‘flowplayer_object’, get_bloginfo( ‘stylesheet_directory’ ) . ‘/_/js/flowplayer/flowplayer-object-creator.js’, array(), // these are your dependencies, if you need jQuery or something, it needs to go in that array false, // set a version if you want true … Read more

Which action to hook wp_enqueue_script to? wp_head or wp_enqueue_scripts? [duplicate]

I took a long time figure out the right way for this! Here’s what I follow now: Use case: In a plugin’s admin page Hook: admin_print_scripts-<page hook> OR <the php file name for your plugin> $hook = add_menu_page(…) / add_submenu_page(…); add_action(‘admin_print_scripts-‘.$hook, ‘my_callback’); Use case: On all admin pages Hook: admin_print_scripts add_action(‘admin_print_scripts’, ‘my_callback’); Use case: On … Read more

Add script to footer – on post editor

Hook into ‘admin_footer-post-new.php’ and ‘admin_footer-post.php’, check the global variable $post_type: add_action( ‘admin_footer-post-new.php’, ‘wpse_73692_script’ ); add_action( ‘admin_footer-post.php’, ‘wpse_73692_script’ ); function wpse_73692_script() { if ( ‘post’ !== $GLOBALS[‘post_type’] ) return; ?> <script>alert( ‘<?php echo $GLOBALS[‘post_type’];?>’ );</script> <?php }

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