Use page Title in Gutenberg custom banner block

Due to the getDocumentTitle selector being deprecated as mentioned here https://stackoverflow.com/questions/51674293/use-page-title-in-gutenberg-custom-banner-block/51792096#comment92130728_51792096 I managed to get it working with a slight tweak to the code by Jim-miraidev var GetTitle = function GetTitle(props) { return el(“h1”, {className: “jab-banner-title”}, props.title); }; var selectTitle = withSelect(function (select) { var title; if (typeof select(“core/editor”).getPostEdits().title !== ‘undefined’) { title = select(“core/editor”).getPostEdits().title; … Read more

Hide or show Gutenberg custom block using date range

Here’s an untested suggestion, to remove an HTML block of type: <!– wp:block/timed-block {“dateFrom”:”2018-11-14″, “dateTo”:”2018-12-18″} –> <section> … </section> <!– /wp:block/timed-block –> from the rendered content, using the render_block filter (available in 5.0+): add_filter( ‘render_block’, function( $block_content, $block ) { // Remove the block/timed-block from the rendered content. if ( ‘block/timed-block’ === $block[‘blockName’] ) { … Read more

Add classname to Gutenberg block wrapper in the editor?

Actually it can be done with the filter: const { createHigherOrderComponent } = wp.compose; const withCustomClassName = createHigherOrderComponent( ( BlockListBlock ) => { return ( props ) => { if(props.attributes.size) { return <BlockListBlock { …props } className={ “block-” + props.attributes.size } />; } else { return <BlockListBlock {…props} /> } }; }, ‘withClientIdClassName’ ); wp.hooks.addFilter( … Read more

Disable block from editor based on post type

You can use the allowed_block_types hook: <?php function wpse_allowed_block_types($allowed_block_types, $post) { // Limit blocks in ‘post’ post type if($post->post_type == ‘post’) { // Return an array containing the allowed block types return array( ‘core/paragraph’, ‘core/heading’ ); } // Limit blocks in ‘page’ post type elseif($post->post_type == ‘page’) { return array( ‘core/list’ ); } // Allow … Read more

Add colors to existing color palette without replacing it

You can merge palettes $existing = get_theme_support( ‘editor-color-palette’ ); $new = array_merge( $existing[0], array( array( ‘name’ => __( ‘Strong magenta’, ‘themeLangDomain’ ), ‘slug’ => ‘strong-magenta’, ‘color’ => ‘#a156b4’, ), array( ‘name’ => __( ‘Light grayish magenta’, ‘themeLangDomain’ ), ‘slug’ => ‘light-grayish-magenta’, ‘color’ => ‘#d0a5db’, ), )); add_theme_support( ‘editor-color-palette’, $new);