beyondwords_player_script_onload

Filters the onload attribute of the BeyondWords Player script.

Note that the strings should be in double quotes, because the output of this is run through esc_js() before it is output into the DOM.

Parameters

$onload string

The string value of the onload script.


$params array

The SDK params for the current post, including projectId and contentId.


Example 1

Append a custom command to the default onload script.

function my_beyondwords_player_script_onload( $onload, $params ) {
    return $onload . 'initializeCustomUserInterface();'; }
}
add_filter( 'beyondwords_player_script_onload', 'my_beyondwords_player_script_onload', 10, 2 );

Example 2

Log the player params to the browser console before the player initializes.

function my_beyondwords_player_script_onload( $onload, $params ) {
     // Console log the params we pass to the SDK
     $my_command = 'console.log("🔊", ' . wp_json_encode( $params, JSON_FORCE_OBJECT | JSON_UNESCAPED_SLASHES ) . ');';

     // Prepend the command to the default onload script
     return $my_command . $onload;
}
add_filter( 'beyondwords_player_script_onload', 'my_beyondwords_player_script_onload', 10, 2 );

Changelog

Last updated