Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to disable specific heading levels in the Editor #322

Closed
ndiego opened this issue Oct 22, 2024 · 0 comments
Closed

How to disable specific heading levels in the Editor #322

ndiego opened this issue Oct 22, 2024 · 0 comments
Labels

Comments

@ndiego
Copy link
Member

ndiego commented Oct 22, 2024

This would be a snippet that provides an example of the heading-level curation options available in WordPress 6.7.

The snippet will show you how to disable H1, H5, and H6 in the Heading block for all users who are not administrators using PHP.

function example_modify_heading_levels_globally( $args, $block_type ) {

    $is_administrator = current_user_can( 'edit_theme_options' );

    if ( 'core/heading' !== $block_type || $is_administrator ) {
        return $args;
    }

    // Remove H1, H5, and H6.
    $args['attributes']['levelOptions']['default'] = [ 2, 3, 4 ];

    return $args;
}
add_filter( 'register_block_type_args', 'example_modify_heading_levels_globally', 10, 2 );
@WordPress WordPress locked and limited conversation to collaborators Oct 22, 2024
@ndiego ndiego converted this issue into discussion #323 Oct 22, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Projects
None yet
Development

No branches or pull requests

1 participant