{"id":4042,"date":"2023-08-11T13:50:06","date_gmt":"2023-08-11T11:50:06","guid":{"rendered":"https:\/\/www.knowboard.de\/?p=4042"},"modified":"2023-08-11T13:50:08","modified_gmt":"2023-08-11T11:50:08","slug":"gutenberg-modifying-core-block-default-attribute-values","status":"publish","type":"post","link":"https:\/\/www.knowboard.de\/gutenberg-modifying-core-block-default-attribute-values\/","title":{"rendered":"Gutenberg: Modifying Core Block Default Attribute Values"},"content":{"rendered":"\n
How to make images automatically centered\u00a0<\/p>\n\n\n\n
In case you didn\u2019t know:<\/p>\n\n\n\n
wp.hooks.addFilter( 'blocks.registerBlockType', 'rudr\/img', ( settings, name ) => {\n\n\tif( 'core\/image' === name ) {\n\n\t\treturn lodash.assign( {}, settings, {\n\t\t\tattributes: lodash.assign( {}, settings.attributes, { \n\t\t\t\talign: {\n\t\t\t\t\ttype: 'string', \n\t\t\t\t\tdefault: 'center'\n\t\t\t\t} \n\t\t\t} )\n\t\t} )\n\t\t\n }\n\n return settings\n\t\n})<\/code><\/pre>\n\n\n\n