Skip to main content

Yoast SEO: Filtering Yoast Blocks

As of Yoast SEO 8.2, we've added our first two structured data blocks: The FAQ block and the How-To block.

Available blocks

Currently, the following blocks are available within Yoast SEO

BlockNamespace
FAQ blockyoast/faq-block
How-To blockyoast/how-to-block

Example

Although WordPress allows you to filter out Blocks by utilizing the allowed_block_types filter, this filter contains some limitations. A better approach to filter out Blocks, is to use a JavaScript implementation. Please note that this also means you have to register a JavaScript file via the wp_enqueue_script method in your own plugin or theme (i.e. functions.php), as follows:

// MyCustomPlugin.php
<?php
// Your plugin code here.

wp_enqueue_script(
'my-custom-blocks-filter',
plugins_url( 'js/MyCustomBlocksFilter.js', __FILE__ ),
[],
'1.0',
true
);

Let's say that you want to only load the FAQ block out of the list of Yoast structured data blocks, and thus want to filter out the How-To block:

// js/MyCustomBlocksFilter.js
const hiddenBlocks = [ 'yoast/how-to-block' ];

wp.blocks.getBlockTypes().forEach( function( block ) {
if ( block.name && hiddenBlocks.includes( block.name ) ) {
wp.blocks.unregisterBlockType( block.name );
}
} );

Inverting the logic of the if-statement (i.e. negating hiddenBlocks.includes( block.name )), will allow you to limit what blocks you do want to be loaded.