1/18/2024 0 Comments Enqueue javascript wordpress themeIn that case, you will not be able to use enqueue_block_assets since this hook does not enqueue assets in the content of the iframed Editor prior to 6.3.Īs an alternative, you can use enqueue_block_editor_assets so long as the enqueued stylesheet contains at least one of the following selectors. Suppose you are building a plugin or theme that requires backward compatibility to 6.2 or lower while maintaining compatibility with WordPress 6.3. Top ↑ Backward compatibility and known issuesĪs a general rule, when you enqueue assets in the iframed Editor, they will also be enqueued when the Editor is not iframed so long as you are using WordPress 6.3+. See the WordPress Developer Blog article Leveraging theme.json and per-block styles for more performant themes for more details. Coupled with theme.json, this is one of the best methods of styling blocks. The wp_enqueue_block_style() function allows you to load per-block stylesheets in the Editor and on the front end. Editor-specific stylesheets should almost always be added with add_editor_style() or wp_enqueue_block_style(). If you need to enqueue Editor JavaScript in a theme, you can use either enqueue_block_assets or enqueue_block_editor_assets as outlined above. See the Block Metadata article for more details. You are able to enqueue assets for the Editor, the front end, or both. When building a block, block.json is the recommended way to enqueue all scripts and styles that are specifically required for the block itself. ![]() **įunction example_enqueue_editor_assets() īeginning in WordPress 6.3, you can also use this method of modifying Editor settings to change styles dynamically with JavaScript. not the user-generated content), you should use the enqueue_block_editor_assets hook coupled with the standard wp_enqueue_script and wp_enqueue_style functions.Įxamples might be adding custom inspector or toolbar controls, registering block styles and variations in Javascript, registering Editor plugins, etc. Whenever you need to enqueue assets for the Editor itself (i.e. There are different hooks to use depending on the answers to these questions, and if you are building a block or a theme, there are additional approaches to consider. The Editor versus Editor contentīefore enqueueing assets in the Editor, you must first identify what you are trying to target.ĭo you want to add styling or JavaScript to the user-generated content (blocks) in the Editor? Or do you want to modify the Editor user interface (UI) components or interact with Editor APIs? This could include everything from creating custom block controls to registering block variations. This guide assumes you are looking to enqueue assets for the iframed Editor, but refer to the backward compatibility section below for additional considerations.įor more information about why the Editor is iframed, please revisit the post Blocks in an iframed (template) editor. ![]() Updates are encouraged.Īs of WordPress 6.3, the Post Editor is iframed if all registered blocks have a Block API version 3 or higher and no traditional metaboxes are registered. The approaches outlined here represent the recommended practices but keep in mind that this resource will evolve as WordPress does. ![]() This guide is designed to be the definitive reference for enqueueing assets (scripts and styles) in the Editor. Browse: Home / Block Editor Handbook / How-to Guides / Enqueueing assets in the Editor Enqueueing assets in the Editor Edit
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |