Skip to main content

window.benecasterFrontend.init()

Utilities Free
window.benecasterFrontend.init( root?: Element | Document ): void

A JavaScript function, not a PHP one. Wires the Benecaster widgets inside root that were put on the page after it loaded. Benecaster’s front-end script wires everything it finds once, when the page loads; markup inserted later — a block preview, an Elementor widget, a tab or modal filled by AJAX — is missed, so a QR code stays blank and its copy and download buttons do nothing. Call this after inserting the markup.

It covers [benecaster_qr_code] (draws the code and shows its SVG and PNG download buttons), the feed URL widget (Copy, and the two-step Reset), and the episode-share Copy link button.

Parameters

Name Type Default Required Description
root Element|Document document No Where to look for Benecaster widgets. Defaults to document. The element itself counts, so passing the widget's own element works. Anything that is not a DOM node is ignored rather than thrown on.

Return Value

Type: void

Nothing.

Example

// After your own code has put Benecaster shortcode output into `container`:
window.benecasterFrontend?.init( container );

// Elementor: re-run for each widget as it renders.
jQuery( window ).on( 'elementor/frontend/init', () => {
    elementorFrontend.hooks.addAction( 'frontend/element_ready/my-widget.default', ( $scope ) => {
        window.benecasterFrontend?.init( $scope[ 0 ] );
    } );
} );

Notes

Call it as often as you like. It is safe to run repeatedly on the same markup, and after every preview re-render is the expected use. Nothing is wired twice, and a QR code already drawn is not redrawn.

It does not count a play. The web player's play beacon is deliberately left out, because a block preview re-renders on every change in the editor. A player on a real page load is counted as usual. There is no supported way to fire the beacon by hand.

It does not cover the account page's interactive parts — data export, avatar upload, and the Supporter Wall controls. Those run once, when the page loads.

Needs the benecaster-frontend script on the page. Every shortcode that uses it loads it when it renders. In the block editor, enqueue it yourself from enqueue_block_assets — the handle is registered on init, so it exists there (see the recipe Load Benecaster's front-end styles into the block editor). Use the optional-chaining call shown above if your script can run where the handle is not loaded.

window.benecasterFrontend also carries the REST URL, nonce and strings Benecaster's own script reads. Those keys are not part of the API; only init, seek and getPlayer are.

Need this built rather than just documented? See our services →