` before it is being rendered. ```php add_action('blockstudio/render/footer', function($output, $blocks) { if ($blocks['ui/heading']) { $output .= ''; } return $output; }, 10, 2); ```
Below you'll find a list of all available PHP hooks that can be used to extend or adjust the functionality of the plugin.
This filter allows you to adjust the path of the block folder. By default, this
is blockstudio
inside the currently active theme. Alternatively it is possible
to create a new
instance for multiple
source directories.
add_action('blockstudio/path', function() { $path = get_stylesheet_directory() . '/blocks'; return $path; });
Copy
This action fires after the plugin has registered all blocks.
add_action('blockstudio/init', function() { // do something });
Copy
This action fires after the plugin has registered all blocks of a specific instance.
add_action('blockstudio/init/$instance', function() { // do something });
Copy
This action fires before the plugin has registered all blocks.
add_action('blockstudio/init/before', function() { // do something });
Copy
This action fires before the plugin has registered all blocks of a specific instance.
add_action('blockstudio/init/$instance', function() { // do something });
Copy
This filter allows you to adjust the output of a block before it is rendered.
add_filter('blockstudio/blocks/render', function ($value, $block, $isEditor, $isPreview) { if ($block->name === 'blockstudio/my-block') { $value = str_replace('%CONTENT%', 'Replace in frontend', $value); if ($isEditor) { $value = str_replace('%CONTENT%', 'Only replace in editor', $value); } if ($isPreview) { $value = str_replace('%CONTENT%', 'Only replace in preview', $value); } } return $value; }, 10, 4);
Copy
This filter allows you to adjust the data of the block.json file before it is registered.
add_filter('blockstudio/blocks/meta', function ($block) { if (strpos($block->name, 'marketing') === 0) { $block->blockstudio['icon'] = '<svg></svg>'; } return $block; });
Copy
The above code would change the icon of all blocks starting with marketing.
This filter allows you to add custom conditions which can be used within blocks.
add_filter('blockstudio/blocks/conditions', function ($conditions) { $conditions['purchasedProduct'] = userHasPurchasedProduct(); return $conditions; });
Copy
This filter allows you to adjust the attributes of a block before the block is registered. See Filtering for more information.
add_filter('blockstudio/blocks/attributes', function ($attribute, $block) { if (isset($attribute['id']) && $attribute['id'] === 'lineNumbers') { $attribute['default'] = true; $attribute['conditions'] = [ [ [ 'id' => 'language', 'operator' => '==', 'value' => 'css', ] ] ]; } return $attribute; }, 10, 2);
Copy
This filter allows you to adjust the attributes of a block before it is rendered. See Filtering for more information.
add_filter('blockstudio/blocks/attributes/render', function ($value, $key, $block) { if ( $key === 'copyButton' && $block['name'] === 'blockstudio-element/code' ) { $value = true; } return $value; }, 10, 3);
Copy
This filter allows you to add custom data to the options of a checkbox
,
select
or radio
field. See Populating options for more information.
add_filter('blockstudio/blocks/attributes/populate', function ($options) { $options['customData'] = [ [ 'value' => 'custom-1', 'label' => 'Custom 1', ], [ 'value' => 'custom-2', 'label' => 'Custom 2', ], [ 'value' => 'custom-3', 'label' => 'Custom 3', ], ]; return $options; });
Copy
This filter allows you to adjust the output of the useBlockProps
content.
add_filter('blockstudio/blocks/components/useblockprops/render', function ($attributes, $block) { if ($block->name === 'blockstudio/title') { $attributes['class'] = $attributes['class'] . ' new-class'; } return $attributes; }, 10, 2);
Copy
This filter allows you to adjust the output of the <InnerBlocks />
content.
add_filter('blockstudio/blocks/components/innerblocks/render', function ($value, $block) { if ($block->name === 'blockstudio/columns') { $value = str_replace('%CONTENT%', 'replace', $value); } return $value; }, 10, 2);
Copy
This filter allows you to remove the <InnerBlocks />
wrapper from the
frontend.
add_filter('blockstudio/blocks/components/innerblocks/frontend/wrap', function ($render, $block) { if ($block->name === 'blockstudio/my-block') { $render = false; } return $render; }, 10, 2);
Copy
This filter allows you to adjust the output of the <RichText />
content.
add_filter('blockstudio/blocks/components/richtext/render', function ($value, $block) { if ($block->name === 'blockstudio/title') { $value = str_replace('%CONTENT%', 'replace', $value); } return $value; }, 10, 2);
Copy
This filter allows you to adjust the path of the blockstudio.json
file. By
default, this is blockstudio.json
inside the currently active theme.
add_filter('blockstudio/settings/path', function() { $path = get_stylesheet_directory() . '/settings'; return $path; });
Copy
This filter allows you to enable the editor for specific user IDs.
add_filter('blockstudio/settings/users/ids', function() { return [1]; });
Copy
This filter allows you to enable the editor for specific user roles.
add_filter('blockstudio/settings/users/roles', function() { return ["administrator","editor"]; });
Copy
This filter allows you to enable/disable the enqueueing of assets in frontend and editor.
add_filter('blockstudio/settings/assets/enqueue', function() { return true; });
Copy
This filter allows you to enable/disable the minification of CSS.
add_filter('blockstudio/settings/assets/minify/css', function() { return false; });
Copy
This filter allows you to enable/disable the minification of JS.
add_filter('blockstudio/settings/assets/minify/js', function() { return false; });
Copy
This filter allows you to enable/disable the processing of SCSS in .css files.
add_filter('blockstudio/settings/assets/process/scss', function() { return false; });
Copy
This filter allows you to enable/disable the processing of .scss files to CSS.
add_filter('blockstudio/settings/assets/process/scssFiles', function() { return true; });
Copy
This filter allows you to enable/disable Tailwind.
add_filter('blockstudio/settings/tailwind/enabled', function() { return false; });
Copy
This filter allows you to add a custom Tailwind configuration.
add_filter('blockstudio/settings/tailwind/config', function() { return [ "theme" => [ "extend" => [ "colors" => [ "primary" => "pink" ] ] ] ]; });
Copy
This filter allows you to enable/disable the formatting of code upon saving.
add_filter('blockstudio/settings/editor/formatOnSave', function() { return false; });
Copy
This filter allows you to enqueue additional assets in the editor.
add_filter('blockstudio/settings/editor/assets', function() { return ["my-stylesheet","another-stylesheet"]; });
Copy
This filter allows you to add additional markup to the end of the editor.
add_filter('blockstudio/settings/editor/markup', function() { return '<style>body { background: black; }</style>'; });
Copy
This filter allows you to disable the loading of blocks inside the Block Editor.
add_filter('blockstudio/settings/blockEditor/disableLoading', function() { return false; });
Copy
This filter allows you to add stylesheets whose classes should be available for choice in the class field.
add_filter('blockstudio/settings/blockEditor/cssClasses', function() { return ["my-stylesheet","another-stylesheet"]; });
Copy
This filter allows you to add stylesheets whose CSS variables should be available for autocompletion in the code field.
add_filter('blockstudio/settings/blockEditor/cssVariables', function() { return ["my-stylesheet","another-stylesheet"]; });
Copy
This filter allows you to enable the block library.
This filter allows you to enable the block library.
add_filter('blockstudio/settings/library', function() { return false; });
Copy
This filter allows you to enable or disable context file generation for LLM tool integration. When enabled, the context file assembles up-to-date block data, Blockstudio settings of the current install, all relevant schemas, and Blockstudio documentation into a single source for use with AI development tools.
add_filter('blockstudio/settings/ai/enableContextGeneration', function() { return false; });
Copy
This filter allows you to disable the asset processing and enqueueing of a specific asset type.
add_filter("blockstudio/assets/enable", function ($value, $data) { if ($data['type'] === 'css') { return false; } return true; }, 10, 2);
Copy
This filter allows you to add additional paths to the @import
statement of the
SCSS compiler.
add_filter('blockstudio/assets/process/scss/importPaths', function() { $paths[] = get_template_directory() . '/src/scss/'; return $paths; });
Copy
This filter allows you to adjust the content of the CSS file before it is being compiled.
add_filter('blockstudio/assets/process/css/content', function($content) { $content = str_replace('background-color: red;', 'background-color: blue;', $content); return $content; });
Copy
This filter allows you to adjust the content of the JS file before it is being compiled.
add_filter('blockstudio/assets/process/js/content', function($content) { $content = str_replace('console.log("hi");', 'console.log("hello");', $content); return $content; });
Copy
This filter allows you to adjust the output of the page before it is being rendered.
add_action('blockstudio/render', function($output, $blocks) { if ($blocks['ui/heading']) { $output = str_replace('<h1', '<h1 class="text-4xl font-semibold mb-4"', $output); } return $output; }, 10, 2);
Copy
This filter allows you to adjust the output of the <head>
tag before it is
being rendered.
add_action('blockstudio/render/head', function($output, $blocks) { if ($blocks['ui/heading']) { $output .= '<style>h1 { color: black; }</style>'; } return $output; }, 10, 2);
Copy
This filter allows you to adjust the output of the </body>
before it is being
rendered.
add_action('blockstudio/render/footer', function($output, $blocks) { if ($blocks['ui/heading']) { $output .= '<style>h1 { color: black; }</style>'; } return $output; }, 10, 2);
Copy