![]() ![]() And wp-edit-blocks for styles in the editor. These are wp-element, wp-blocks, wp-components, wp-i18n, and wp-editor for JS. When you’re building blocks for the new Gutenberg editor there are a few JavaScript libraries that you’ll want to include within the dependencies parameter of your wp_enqueue_script function. In the case you have some style that needs to only be included within the frontend and not the editor you could use the enqueue_block_assets hook and run an ! is_admin() check to enqueue your script or style. This again would use enqueue_block_assets. Since the idea behind Gutenberg is to tie the frontend and editor content together visually you’ll most likely have the bulk of your CSS displayed on both the frontend and editor. In that case you can load those scripts with enqueue_block_assets. For example, if you’re building a slider block you would want the sliding functionality to work in both instances. In some cases you may need JavaScript that runs in both the frontend or the backend. This could be something like focus states for an input or other indicators to show the user what is editable in the editor that isn’t needed on the frontend. In that case you’ll want to enqueue those using enqueue_block_editor_assets as well. You may also have styles that are only relevant to the editor. Since the main JavaScript for creating blocks is only needed in the admin editor you’ll want to use enqueue_block_editor_assets to include it. The new hooksĮnqueue_block_editor_assets – This can be used to enqueue block scripts and styles in the admin editor only.Įnqueue_block_assets – This is used to enqueue block scripts and styles in both the admin editor and frontend of the site. As well as the wp_enqueue_script and wp_enqueue_style functions. This is done by using two new hooks introduced to WordPress specifically for enqueueing block assets. Since Gutenberg blocks are built with JavaScript we’ll need to enqueue our scripts and any styles associated with the block. To get started building blocks for Gutenberg we’re going to need a way to let WordPress know our blocks exist.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |