Skip to content

Instantly share code, notes, and snippets.

@junaidbhura
Created December 30, 2019 02:01
Show Gist options
  • Save junaidbhura/8ebcfea25cd0077d5847439ddac2ffd4 to your computer and use it in GitHub Desktop.
Save junaidbhura/8ebcfea25cd0077d5847439ddac2ffd4 to your computer and use it in GitHub Desktop.
/**
* Anchors.
*/
// Variables.
import wp from 'wp';
const { addFilter } = wp.hooks;
import includes from 'lodash/includes';
// Add anchor support to these blocks.
const blocks = [
'core/columns',
];
// Attributes.
addFilter(
'blocks.registerBlockType',
'jb/anchors',
( props, name ) => {
if ( ! includes( blocks, name ) ) {
return props;
}
const supports = {
...props.supports,
anchor: true,
};
props = { ...props, supports };
const attributes = {
...props.attributes,
anchor: {
type: 'string',
source: 'attribute',
attribute: 'id',
selector: '*',
},
};
props = { ...props, attributes };
return props;
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment