When you embark on creating a new post for your website through Posts -> Add New Post, you’ll encounter an array of core Gutenberg blocks such as Paragraph, Heading, Image, Video, Embed, Code, and more, all seamlessly integrated into WordPress by default.
As you scroll a bit further down, you’ll discover a block category labeled “Newsletter Glue” (assuming the NG plugin is active). Within this category, you’ll encounter blocks such as Heading, Image, List, and others, which offer enhanced capabilities compared to the standard core blocks.
When you navigate to create a campaign via Newsletters -> Emails -> Add Campaign, you’ll exclusively encounter Newsletter Glue’s blocks without the presence of core blocks or even custom blocks you might have developed. This setup intentionally filters and displays only registered blocks within this context.
How can I filter In the core blocks inside the block list?
To filter and include specific core blocks inside the block list, you need to use the actual block names of the core blocks provided by WordPress. Below is a reference list of some common core blocks along with their block names that you can use for filtering:
Block Name | Block Type |
Paragraph | core/paragraph |
Heading | core/heading |
Image | core/image |
List | core/list |
Quote | core/quote |
Video | core/video |
Audio | core/audio |
File | core/file |
Gallery | core/gallery |
To filter and specifically include certain block types like core/paragraph
, core/heading
, or a custom block such as create-block/copyright-date-block
in the block list within a custom WordPress theme or plugin, you can use the newsletterglue_allowed_block_list
filter inside the functions.php or inside the initialisation area of your theme or plugin. This filter allows you to control which blocks are available in the editor interface. Below is a detailed example of how you can achieve this:
// Define a custom function to modify the allowed block types
function custom_allowed_block_types($allowed_blocks) {
// Add specific block types that you want to include in the block list
$allowed_block_types = array_merge($allowed_blocks, array(
'core/paragraph', // Include Paragraph block
'core/heading', // Include Heading block
'create-block/copyright-date-block' // Include Custom block (e.g., copyright-date-block)
// Add more block types as needed
));
return $allowed_block_types;
}
// Hook into the 'newsletterglue_allowed_block_list' filter
add_filter('newsletterglue_allowed_block_list', 'custom_allowed_block_types', 60);
Important note
To ensure that your custom function name is unique and avoids conflicts with other functions in your WordPress theme or plugin, it’s recommended to use a unique function name or add prefix for the function name. This helps in maintaining clarity and preventing naming collisions with other functions, especially when working within larger codebases or when integrating third-party plugins.