1. Home
  2. v3
  3. How to filter in the core blocks of WordPress into Newsletter Glue?

How to filter in the core blocks of WordPress into Newsletter Glue?

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.

Core Blocks

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.

Newsletter Glue 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 NameBlock Type
Paragraphcore/paragraph
Headingcore/heading
Imagecore/image
Listcore/list
Quotecore/quote
Videocore/video
Audiocore/audio
Filecore/file
Gallerycore/gallery
Some core blocks

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);
Core, custom blocks visible in the block list

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.

Updated on May 1, 2024

Was this article helpful?

Get more help
Can't find the answer you're looking for? Get in touch.
Contact support