Gutenberg RangeControl

When using a control that modifies a block attribute, you need to set the value of the control to the value of the attribute and the onChange function needs to change the attribute using the setAttributes function: el( RangeControl, { label: ‘Columns’, value: props.attributes.my_attribute, initialPosition: 1, min: 0, max: 3, onChange: function( val ) { … Read more

Unable To Call Javascript With Enqueue

In WP jQuery works in compatibility mode by default. It means that the typical $ shortcut for jQuery doesn’t work, so it doesn’t conflict with any other JavaScript libraries that use the dollar sign also, like MooTools or Prototype. So you should use jQuery instead of $ in your JS file. Of course you can … Read more

Update media library attachments

edit: ok after working on this for the last hour ive finally found a solution that works without affecting uploading and without messing with ignore or reset wp.media.frame.on(‘open’, function() { if (wp.media.frame.content.get() !== null) { // this forces a refresh of the content wp.media.frame.content.get().collection._requery(true); // optional: reset selection wp.media.frame.content.get().options.selection.reset(); } }, this);

How to read inline-CSS from Gutenberg block?

Turns out Gutenberg has another way of storing attribute values: the block’s comment delimiter: If no attribute source is specified, the attribute will be saved to (and read from) the block’s comment delimiter. source When I inspected the database entry, I indeed found the size attribute there: <!– wp:XXX {“size”:48} –> <div>…</div> <!– /wp:XXX –> … Read more