There are issues in the answer marked as correct. It will break the alignment class functionality, and is not actually adding to the classList, instead it is overriding it. And you will only be able to use that one solution for your whole theme.
Instead you can use “registerBlockStyle()” to add a style variation to the list block, and set “isDefault” to true for it to use that class/style but still be able to skip using it, or add a multiple variations if you want.
the wp.domReady() makes sure that it loads when it should and applies the changes
wp.domReady( () => {
wp.blocks.registerBlockStyle( 'core/list', {
name: 'custom-list-style',
label: 'Custom list style',
isDefault: true
} );
} );
Related Posts:
- Remove left alignment option in core/image block
- Changing Gutenberg / WP block editor width only on pages, not posts or other taxonomies
- How can I filter block registration based on post-type? (Block alignment settings)
- Remove CSS & JS files from WordPress Main Page For Increase Pagespeed?
- This code works, but breaks the media uploader. How do I integrate it in a way that won’t?
- Modify Gutenberg blocks quick inserter defaults
- How to add defer=”defer” tag in plugin javascripts?
- How would one modify the filtering Gutenberg applies to pasted content?
- Gutenberg: Is there a way to know if current block is inside InnerBlocks?
- Why is javascript allowed in my post content?
- How to pass/get data to/from the WooCommerce data-product_variations object?
- How can I extend the Gutenberg table block transform to allow colspans/rowspans on pasted table elements?
- Changing text within the Block Editor
- Adding a class to the body_class function
- AJAX filter posts on click based on category
- Add classname to the_category() function?
- Filter Gutenberg Blocks Content
- How to remove google font in WordPress for only single page?
- How do I replace a render_callback function for a block?
- Gutenberg disable the “block” tab in right sidebar
- Where is this inline CSS code [closed]
- How to center oEmbedded content
- How to change the order of HTML output of a core block?
- Add attribute to script loaded by the theme
- When to use add_action when registering/enqueuing scripts
- Gutenberg – Add align controls to a custom block
- Can the wordpress color palettes by changed through Javascript?
- Header image automatically changes depending on season
- Inline Styles on all native blocks
- How to link the whole list item in Gutenberg’s latest posts block?
- add_filter(allowed_block_types) -> adding core/paragraph bugs Gutenberg editor
- Set default terms for new posts / CPTs
- Redirect to another page using contact form 7? [closed]
- Detect when gutenberg editor title is available in Dom after editor load
- Gutenberg Block – Post Featured Image Filter Hook
- Set default value for “Additional CSS class(es)” for specific block types
- Change login CSS
- How to hide/remove GhostKit component panel in gutenberg block inspector
- Filter for author list in gutenberg core editor
- How do I add tags to entire comments, not just their text
- How to optionally append components to the output of a gutenberg block?
- Problem width wp_insert_post_data and Gutenberg block editor
- WordPress Gutenberg core/heading block (wp-block-heading)
- Changing the category for existing Gutenberg blocks
- “The editor has encountered an unexpected error” After add defer tag to java script
- How do I check if I can use the allowed_block_types filter?
- Add an attribute to the root from functions.php with add_filter
- How to add lazy field in content endpoint using Gutenberg blocks
- How to bridge the gap between dynamic back-end data and front-end output?
- Publish button inside custom field group
- How would I remove an inline googleAPI font script in the the parent theme header.php?
- How to add custom HTML attribute to reusable block div in WordPress admin
- How to change this WP logo and posts url in block editor?
- Background color and background image below element in Contact Form 7 – error tip [closed]
- Limit total tags in the_content
- Are blocks that are converted to patterns no longer filterable through the_content?
- Separate typography controls for titles and meta in a custom block?
- How to use render_block filter in Gutenberg when editing a page?
- WordPress REST API and Backbone JS
- “Invalid parameter(s): attributes” issue in context of “blocks.registerBlockType” filter
- Embed dynamic media query in a Gutenberg block
- Block style variations not enqueued for blocks inside HTML code dynamically rendered via JS
- Core/Image access caption in render_template and in wp.hooks
- Ship block templates or block template parts with plugins
- How can I inject an SVG gradient into the site/theme editor’s head or footer?
- Passing variable from filter
- How to turn this customized core function into a filter/action in functions.php?
- Turn wp_tag_cloud into a front-end filter
- Custom excerpt_more filter not working when tag is present
- Adding an orderby filter, casting postmeta with multiple keys
- contact 7 plugin stops some pages from working properly
- How we make the filter for fornt end user
- Filter image and text from post format
- How to add different CSS for galleries
- How to implement a JavaScript and CSS file for my WordPress homepage?
- What can cause JavaScript and CSS files to be minified?
- Identify admin/logout and more filters
- Add Default WordPress Formatting To Data From External SQL Tables?
- Sanitizing a custom query’s clauses
- How can I display wp_link_pages before a shortcode, if it is used, or display after content?
- Clean/filter HTML inserted to post content by XML RPC
- Filter and Search
- How to separate a specific page’s comments from other comments
- What is the scope and persistence of add_filter() and remove_filter()?
- how to localize the number of wordpress post views?
- Which hook should be used in this case?
- confusion with add_filter
- add_filter with specific thumb names
- post->post_content filter
- Override typo in multiple parent theme files?
- Add HTML to Page Content
- Categorize posts on a page o the basis of category of other post on the same page
- How properly write function to filter content in a template for plugin “multiple content blocks”
- Filter dashboard custom post listing by user
- Taxonomy search filters
- Joining tables not working in the post editor page
- How to reuse parts of WordPress site e.g. header, footer, part of header for multiple WordPress sites?
- How to create a list of terms who’s posts also have a predefined external term?
- Block pattern conflict with custom block
- Use of CSS classes in editor-blocks.css file