Last active
May 1, 2019 01:07
-
-
Save phpbits/348a7d22e68110995ead8606ffd882cb to your computer and use it in GitHub Desktop.
Add Custom Attributes to Core Gutenberg Blocks. View full tutorials at https://jeffreycarandang.com/extending-gutenberg-core-blocks-with-custom-attributes-and-controls/
This file contains 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
/** | |
* WordPress Dependencies | |
*/ | |
const { addFilter } = wp.hooks; | |
/** | |
* Add custom attribute for mobile visibility. | |
* | |
* @param {Object} settings Settings for the block. | |
* | |
* @return {Object} settings Modified settings. | |
*/ | |
function addAttributes( settings ) { | |
//check if object exists for old Gutenberg version compatibility | |
if( typeof settings.attributes !== 'undefined' ){ | |
settings.attributes = Object.assign( settings.attributes, { | |
visibleOnMobile:{ | |
type: 'boolean', | |
default: true, | |
} | |
}); | |
} | |
return settings; | |
} | |
addFilter( | |
'blocks.registerBlockType', | |
'editorskit/custom-attributes', | |
addAttributes | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment