What is the advantage of ‘register_block_type’ (the PHP function) when creating custom blocks?

1.: The register_block_type lets you load additional stylesheets and scripts for your block in the frontend 2.: As you yourself wrote, register_block_type lets you define a dynamic php render_callback function 3.: If you use a render_callback, you can of course use filters within it. EDIT: As the comments pointed out, there is some clarification needed … Read more

gutenberg block – how to force update after attribute changed?

In this instance, you are treating the asynchronous jQuery AJAX call as a synchronous function, resulting in getStoriesList() consistently returning undefined as the function returns immediately after dispatching the HTTP request; trying to access response.status should be consistently throwing ReferenceError: response is not defined. In almost all cases it is more ideal to access data … Read more

Blocks: set a default value for a TextControl

Try setting the default value in your attributes instead of on the TextControl. registerBlockType( ‘cgb/a11ytable’, { title: ‘Accessible Table’, icon: ‘screenoptions’, category: ‘common’, attributes: { numCols: { type: ‘number’, default: 2 // Added default value } }, edit: (props) => { const { attributes: { numCols }, className, setAttributes } = props; return [ el( … Read more

Are there ways to make the Gutenberg editor wider? And the HTML-block higher?

You have to enqueue first the style editor css function legit_block_editor_styles() { wp_enqueue_style( ‘legit-editor-styles’, get_theme_file_uri( ‘/style-editor.css’ ), false, ‘2.3’, ‘all’ );} add_action( ‘enqueue_block_editor_assets’, ‘legit_block_editor_styles’ ); Then you have to create that style-editor.css file inside your theme and then add this inside that file: .wp-block { max-width: 100%;}

Looking for all available options of Gutenberg Block

Option 1 Browse the block-library package in the Gutenberg’s GitHub repository, and find the block metadata in a JSON file named block.json of the specific block. For example, for the core/image block, you can find the metadata (e.g. all available/supported attributes) here: https://github.com/WordPress/gutenberg/blob/master/packages/block-library/src/image/block.json So basically, the URL format is: https://github.com/WordPress/gutenberg/blob/master/packages/block-library/src/{name}/block.json where {name} is the block … Read more

How do I get the current post ID within a Gutenberg/Block Editor block?

To simply get the value you can call the selector: const post_id = wp.data.select(“core/editor”).getCurrentPostId(); In this case, the post id won’t change, so you could assign the value to a constant outside of the component: const { Component } = wp.element; const { getCurrentPostId } = wp.data.select(“core/editor”); const post_id = getCurrentPostId(); // class component class … Read more

Disable Gutenberg text-Settings in all blocks

The closest I can find in the documentation is disabling custom font size (the text input) and forcing the dropdown font size to only contain “Normal”. add_action(‘after_setup_theme’, ‘wpse_remove_custom_colors’); function wpse_remove_custom_colors() { // removes the text box where users can enter custom pixel sizes add_theme_support(‘disable-custom-font-sizes’); // forces the dropdown for font sizes to only contain “normal” … Read more

Remove block styles in the Block Editor

We start off by finding out which block styles exists via .getBlockTypes(). This will dump it into the console: wp.domReady(() => { // find blocks styles wp.blocks.getBlockTypes().forEach((block) => { if (_.isArray(block[‘styles’])) { console.log(block.name, _.pluck(block[‘styles’], ‘name’)); } }); }); Example output: core/image (2) [“default”, “rounded”] core/quote (2) [“default”, “large”] core/button (2) [“fill”, “outline”] core/pullquote (2) [“default”, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)