How do I add text or message above the featured image area in gutenberg for a CPT

Try this: function wrapPostFeaturedImage( OriginalComponent ) { const currentPostType = wp.data.select( ‘core/editor’ ).getCurrentPostType(); // Do nothing, if the post type is not rt_brands. if ( ‘rt_brands’ !== currentPostType ) { return OriginalComponent; } return function( props ) { // Your code here. }; } You can also: Conditionally add your filter: // Check if the … Read more

How do I load css in edit screens for the block builder?

To load a custom stylesheet for the WordPress admin screens that manage posts and use the block editor, you can use the admin_enqueue_scripts hook to enqueue your stylesheet. Here’s an example of how you can achieve this: First, create a custom stylesheet (let’s call it admin-custom-styles.css) and place it in your theme or plugin directory. … Read more

No aspect ratio selector in a custom block

Per the developer handbook: This value signals that a block supports some of the CSS style properties related to dimensions. When it does, the block editor will show UI controls for the user to set their values if the theme declares support. So in your theme you’ll need to declare support either by setting appearanceTools … Read more

How to use get_option() in Gutenberg block editor to retrieve global settings?

If your option is enabled in the REST API, e.g. by using register_setting() with ‘show_in_rest’ => true, you can use wp.data.select( ‘core’ ).getSite() to retrieve the value of your option, and to update the option, you can use wp.data.dispatch( ‘core’ ).saveSite(). So for example in your case: To get the option value: wp.data.select( ‘core’ ).getSite()?.autoupdate … Read more

Detect whether a block has server-side render

In PHP, it’s certainly possible to check if a block type is dynamic or whether the block uses server-side rendering. For example for already registered block types, just get the block type object and call its is_dynamic method. $block_registry = WP_Block_Type_Registry::get_instance(); $block_name=”core/latest-posts”; $block_type_object = $block_registry->get_registered( $block_name ); if ( $block_type_object ) { // Note: render_callback … Read more

what is the function of the view.js file?

The filename is not really relevant. You should check block.json to see where the file is actually being used. I would guess that it’s being used for the viewScript property, in which case you can check its purpose by looking for the documentation for that property, rather than anything about “view.js” alone. As noted in … Read more