Gutenberg Editor: dynamicaly change slug field with an ACF field

I’ve found a way to dynamicaly change the slug field with the short title custom field. jQuery(document).ready(() => { const acfField = ‘field_61f8bacf53dc5’; const inputShortTitle = document.getElementById(‘acf-‘ + acfField); const slugify = (str) => { return str.toLowerCase().replace(/ /g, ‘-‘) .replace(/-+/g, ‘-‘).replace(/[^\w-]+/g, ”); } const updateSlug = () => { wp.data.dispatch(‘core/editor’).editPost({slug: slugify(inputShortTitle.value)}); } if (inputShortTitle !== … Read more

How to remove specific panels in the editor (Gutenberg) when editing a block (via right panel)?

Removing specific panels or features for a block is done on a per block basis using various hooks (https://github.com/WordPress/gutenberg/issues/15450#issuecomment-635255936) Update (August 2021) Removing specific panels (that would allow for customization of a block) can now be done through the theme.json aka global settings and styles which allows you to customize settings (colors, typography, etc) for … Read more

Best practices for CPT without using an editor [closed]

I have used the custom block option quite extensively. I enable the editor for the custom post type, but use a custom template with template_lock set to true: ‘template’ => array( array(‘pb/custom-block-name’), ), ‘template_lock’ => true Then I use the allowed_block_types_all filter to only allow that custom block for the post type: function pb_allowed_block_types($allowed_block_types, $block_editor_context) … Read more

Using applyFormat (from @wordpress/rich-text) to make persistent changes to Gutenberg’s rich text value

I finally figured it out. Just posting it here if anyone needs to do this as the Gutenberg documentation lacks code examples. With reference to the below code, blockIndex is the block you are dealing with; and startIndex and endIndex are ranges to annotate in context of the block: // Get latest modified content of … Read more

Gutenberg translation is not working

I’ve spent all day debugging this issue, and by looking at the code I can guess we shared the same problems: assuming $script_handle is CUSTOM-block-ref-holder, the PHP file is almost correct. wp_set_script_translations needs the full path to work. In your case, although you probably need to adjust for your path, it should be something like … Read more

Reset data when the field is cleared

That’s not how that component works. onRemove is called when the link is unlinked, via a button that only appears when certain conditions are met: { onRemove && value && ! isEditingLink && ! isCreatingPage && ( <Button className=”block-editor-link-control__unlink” isDestructive variant=”link” onClick={ onRemove } > { __( ‘Unlink’ ) } </Button> ) } https://github.com/WordPress/gutenberg/blob/6eac4a26f143c7378c3b39b5a83271538f36dfa9/packages/block-editor/src/components/link-control/index.js#L270 When … Read more