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 defaults in all other post types
else {
return $allowed_block_types;
}
}
add_filter('allowed_block_types', 'wpse_allowed_block_types', 10, 2);
?>
Tweak with as many or as few conditions as you need. You can also enable non-Core blocks by identifying their namespace and name and putting those in the array.
Related Posts:
- Hide gutenberg option blocks
- WordPress v5.0.3 Gutenberg & JS error “Uncaught SyntaxError: missing ) after argument list”
- Gutenberg gallery hook errors
- What is the best filter where to use register_block_type?
- @wordpress/hooks use to add actions/filters within multiple plugin
- How to extend custom (non-core) blocks?
- Is it possible to switch Gutenberg’s editor styles when document settings change?
- How do I run an action after a featured image has been selected in the Gutenberg editor?
- WordPress How to reorder Page/Post Settings
- Why does get_post() not return anything?
- How To Apply Different Styles To All Blocks Based on Post Meta Value?
- getSaveContent.extraProps hook for core/post-title doesn’t add new attributes on to the frontend
- How to set Post ID from context to an attribute in child block of Gutenberg Query Loop
- Creating my own “recent blog posts” static Gutenberg block, can’t use react hooks in the frontend
- The enqueue_block_assets is changing the styles of the editor interface
- Unable to trigger a frontend @wordpress/hooks action
- Replacing specific Gutenberg blocks
- Difference between do_action and add_action
- Difference between after_setup_theme and init action hooks?
- get $post in init filter or action?
- How to intercept a 404 error
- Move excerpt meta box to above content editor
- Trigger custom action when setting button pressed
- Which hook if user profile information is updated?
- Extend core block in Gutenberg
- Hook/notify when any option or setting is added or updated
- Which hooks is this? add_action(‘wp’,
- admin_notices after register_uninstall / deactivate_hook
- When using the block.getSaveElement hook can you output different markup based on whether or not you are in the edit view or the live page view?
- Why does wp_enqueue_script ignore my ‘wp_head’ hook?
- action lifecycle
- How to modify an add_action() inside a loop of core function
- Gutenberg disable the “block” tab in right sidebar
- How get list all users who edited post?
- Stuck in redirect loop after using wp_login action
- Hooks for Links Box [duplicate]
- Check if do_action(‘custom_action’) is hooked into?
- wp_login Action hook with conditional tag
- Can I remove WooCommerce main content hook?
- How to alter the query using pre_get_posts hook and is_post_type_archive
- How to update WordPress core or themes and still have my child theme hooks work
- Proper indentation of code generated inside hooks
- How can I count post views of REST API calls and update them in an ACF field?
- How to catch and modify custom field values when a page is updated
- Genesis: How to add content after aside and before the content-sidebar wrap
- new_to_publish fires multiple times
- Plugin init hook
- Is there a hook that fires when a row of wp_sitemeta table is updated?
- Post Meta Emtpy on Publish Using Transition
- How to check post type when using sanitize_title hook?
- How do I trigger a post update within a get_posts() foreach loop?
- Duplicate Cron Jobs Using wp_next_scheduled / wp_schedule_event
- Hook when editing user
- get_post_metadata causing some meta data to fail
- How to change the default mail when admin approuved an user?
- How to modify how the_content outputs a link to an internal page
- load-* hook for dashboard
- What conditions must be met in order to upload .zip file to a multisite WordPress installation?
- How to hook code in ?
- wp_enqueue_script before wp_head
- Is it possible to add the_content filter upon login?
- Use an array of page template slugs and $hook
- wp_logout hook never triggered
- add short description under price
- How do I use pre_option_{option_name} correctly?
- WordPress media library allow uploading fake file
- What hook do I use if I want to update a user profile field when a new user is created?
- How to add custom tab page in backend?
- Add html code in admin page
- Hooking dynamic/variable named hook in all cases
- What hook to add at start of WordPress load
- Knowing if a post is sticky in the ‘save_post’ action. Where do I have to hook?
- How to read and write session data?
- Count when a post of a custom post type is deleted and store it in a theme option
- Can we change the hook firing sequence?
- Intercept loading of a certain page
- Creating custom post on registration in wordpress?
- Display custom user profile fields in wordpress
- profile_update not supplying old data
- Output Redirect Headers on Admin Dashboard Page
- add_image_size not working with after_switch_theme
- wordpress hooks
- Check when a setting has been changed
- add extra parameter in default hook in wordpress
- Exclude WooCommerce terminations from YOAST
- set_post_format called after wp_update_post when using bulk edit?
- add hook restricted only to either plugins or themes?
- How to hook watchdog script for existence of a WP page?
- addaction hook cause redirection problem
- Getting all post/page IDs related to a soon-to-be-deleted tag/cat
- Hooking get_pages()
- Fire a hook programmatically
- Transform .wp-video to the native video player of the browser
- How to add a new link to the default register form’s footer links?
- How to use the password_reset hook to validate new password and display error
- Use wordpress search hooks to search a second database
- Why callback function is not working in wp_head hook?
- woocommerce_add_to_cart_validation max quantity depending on user geoip [closed]
- theme.json is altering Group block HTML
- Not able to set userId and email at wp_set_current_user in Worpdress