Wordpress Audio Player and SmoothState. How to call a callback to reload the player on new pages?

I am using Wordpress Audio Player with a short code in the code on the header.php page.

I also use SmoothState ( http://miguel-perez.imtqy.com/smoothState.js/ ).

What function do I need to call a "callback" to reload the player on new pages?

I am enqueing js and css in functions.php as follows:

wp_enqueue_style( 'wp-mediaelement' ); wp_enqueue_script( 'wp-mediaelement' ); 
+5
source share
1 answer

All that wp_enqueue_script(); does wp_enqueue_script(); , is placed on the script page after checking the dependencies. It will not restart the player for you on different pages. But, as long as you use this function correctly, your script should load on every page. Perhaps your mistake is elsewhere?

From the WordPress documentation on wp_enqueue_script(); :

Associates the script file with the created page at the right time according to the script dependencies if the script has not already been and if all the dependencies are registered.

If Wordpress Audio Player has jQuery as a dependency (probably), your functions.php file should look like this:

 function wpaudioscript() { // Parameters are name, path, dependency, version, loadinfooter // Better explanation here: http://codex.wordpress.org/Function_Reference/wp_enqueue_script wp_enqueue_script( 'name-of-script', get_stylesheet_directory_uri() . '/js/custom_script.js', array( 'jquery' ), 1.0.0, true ); } add_action( 'wp_enqueue_scripts', 'wpaudioscript' ); 

Other notes:

  • You must load your scripts in the application footer to improve performance. Setting the fifth parameter of wp_enqueue_script to true , as in the above example, will do this for you.
  • Many people usually put custom functions like this in their functions.php file, but I find it cleaner to put all my own modifications in a custom module. Smashing Mag is a good description of how to do this .
+1
source

Source: https://habr.com/ru/post/1234390/


All Articles