Initializing scripts in wordpress
Initializing scripts in wordpress
Initializing scripts in wordpress
Similar to Wyck’s answer, but using str_replace instead of regex. script_loader_src and style_loader_src are the hooks you want. <?php add_filter( ‘script_loader_src’, ‘wpse47206_src’ ); add_filter( ‘style_loader_src’, ‘wpse47206_src’ ); function wpse47206_src( $url ) { if( is_admin() ) return $url; return str_replace( site_url(), ”, $url ); } You could also start the script/style URLs with a double slash … Read more
How to load default wordpress scripts
List all non-admin enqueued files
dequeue means it should be removed from the queue. All the scripts in the queue get loaded at page load. Once the page is loaded, you cannot use dequeue to remove the script. Best is to only load the scripts you really need. You might load it conditionally in the constructor based on which page … Read more
Prevent caching when using wp_enqueue_script?
How does your function pw_load_scripts() know about the existence of $dataToBePassed? Is the variable global? Looking at the code you’ve got, I’m guessing that, as far as wp_localize_script() is concerned, $dataToBePassed is a local variable, and it’s probably null.
Dealing with multiple Google maps API calls
Since you didn’t ask clearly I understood that you want to know how to include script to your plugin. If so, do this: wp_enqueue_script( ‘your_plugin_name’, plugin_dir_url( __FILE__ ) . ‘js/your-script.js’, array( ‘jquery’ ),’1.0.0′, true );
It is becuase you didn’t enqueue jquery, replce your mytheme_custom_scripts() function with below code. function mytheme_custom_scripts(){ // include jquery wp_enqueue_script(‘jquery’); wp_enqueue_script( ‘my-test-script’, get_template_directory_uri() . ‘/js/my-jquery-script.js’, array(‘jquery’), ‘1.0’, true ); } and jQuery code like this jQuery(document).ready(function($){ $(‘h1, h2, h3, h4, h5, h6, p, a’).css(‘color’,’pink’); });