lzb/plugin_url
Moves the URL Lazy Blocks builds its own script and style tags from, which is what serving the plugin's assets from a CDN needs.
The default is plugin_dir_url() of the core plugin file, ending in a slash. LazyBlocks_Assets::register_script() and register_style() append a build path and an extension to it, so build/editor.js and build/editor.css are resolved against whatever this filter returns. The file contents are never read through this value. That is lzb/plugin_path, which is why a wrong URL here costs a 404 on the editor bundle rather than a fatal error.
Attributes
| Name | Type | Description |
|---|---|---|
$plugin_url | String | plugin folder URL, with a trailing slash |
Usage
function my_lzb_plugin_url( $plugin_url ) {
// Serve the plugin's built CSS and JS from a CDN mirror of wp-content.
return str_replace( content_url(), 'https://cdn.example.com/wp-content', $plugin_url );
}
add_filter( 'lzb/plugin_url', 'my_lzb_plugin_url' );A return value without the trailing slash produces URLs like .../lazy-blocksbuild/editor.js, so keep it or add it back with trailingslashit(). Asset version strings still come from the .asset.php files on disk, read through lzb/plugin_path, which means a CDN copy has to match the installed build or the browser caches the wrong file against the right version.
The Pro plugin has its own directory and its own filter, lzb_pro/plugin_url. Filtering one leaves the other alone.