Created
December 30, 2019 02:01
-
-
Save junaidbhura/8ebcfea25cd0077d5847439ddac2ffd4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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