Skip to content

Instantly share code, notes, and snippets.

Last active April 7, 2021 15:56
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Apply custom class to Gutenberg block element. View full tutorials at
* External Dependencies
import classnames from 'classnames';
* Add custom element class in save element.
* @param {Object} extraProps Block element.
* @param {Object} blockType Blocks object.
* @param {Object} attributes Blocks attributes.
* @return {Object} extraProps Modified block element.
function applyExtraClass( extraProps, blockType, attributes ) {
const { visibleOnMobile } = attributes;
//check if attribute exists for old Gutenberg version compatibility
//add class only when visibleOnMobile = false
if ( typeof visibleOnMobile !== 'undefined' && !visibleOnMobile ) {
extraProps.className = classnames( extraProps.className, 'mobile-hidden' );
return extraProps;
Copy link

anoopd commented Apr 7, 2021

is it possible to add extraclass to core blocks ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment