How to import the imagesLoaded and Masonry libs that come with WP in a Gutenberg block?

When developing a block with @wordpress/scripts, wp-scripts uses @wordpress/dependency-extraction-webpack-plugin to allow you to import dependencies from WordPress by replacing the import statements with references to the global variables loaded by the enqueued scripts. For example, this: import { useEffect } from ‘@wordpress/element’ Will become: const { useEffect } = wp.element; And wp-element will be added … Read more

How to change the selected Template using javascript?

You are already using the correct action, i.e. wp.data.dispatch( ‘core/editor’ ).editPost(), however, you should instead change the property named template. I.e. wp.data.dispatch( ‘core/editor’ ).editPost( { template: ‘article.php’ } ) Yes, _wp_page_template is the meta key in the database, but in the REST API, a property named template exists in place of direct access on that … Read more

Processing javascript on wordpress

The script tags are only there to contain the JavaScript that will be executed by the browser. You need to tell WordPress to ignore those tags so it doesn’t process them as HTML. One way to do this is to use the “esc_html” function. You’ll need to wrap the script tags in the following code: … Read more