I’d recommend looking at how the existing Button
component works to get a sense of how Gutenberg does things. Specifically it uses a <RichText/>
component (instead of a native <input>
) which allows you to specify the tag name while also supporting user input.
Generally I’d advice against using <input>
elements whenever possible. WordPress makes available a ton of components that can dramatically simplify your work.
For block styles, you may want to look at the styles
attribute you can add to a block’s definition. It will automatically create the UI necessary for a user to switch styles and output CSS classes to the block for styling. It may not match exactly what you have (e.g. btn btn-primary
), but it will line up with the “proper” way of doing things in Gutenberg (e.g. is-style-primary
).
Related Posts:
- Proper, exhaustive documentation for wp.editor etc
- Edit srcset and sizes attributes in Gutenberg image, cover and gallery – blocks
- Add colors to existing color palette without replacing it
- Can you filter posts by meta key with the getEntitityRecords selector?
- WP Gutenberg custom block – generate theme colors from SASS and use them in the inspector and php callback
- create blocks programmtically on theme activation
- Can I customize any WordPress parent block-based theme template files by child theme like a parent classic theme?
- How to support Lazy Loading Assets in a WordPress Theme?
- WordPress Gutenberg Theme: Structure, Hierarchy and Custom Templates
- Gutenberg Reusable Block as part of WordPress Theme page
- How to float an image in Gutenberg
- Gutenberg – editor-font-sizes in functions not working
- Can’t select my block by clicking on it
- Which file handles the block latest posts, I want to examine excerpt handling
- create-guten-block in wordpress theme?
- What VSCode extensions are there for working with block themes? [closed]
- What is the “correct” way to add hooks or similar PHP behavior to a blocktheme?
- Not able to select width of blocks inside of cover block
- How to check if a WordPress core block is active in sidebar
- gutenberg add classes to list items
- How do you replace content generated by custom fields with custom blocks in Block Editor?
- Custom Blocks as part of a theme
- How to wrap all titles generated by Gutenberg “Heading” block with tag
- How to add InnerBlock multiple times in the same block
- Moving post title down the page / Removing a block from a post
- HTML block gutenberg templates
- Gutenberg theme development: how to add “headers” option under styles > colors > elements?
- Change default rel attributes for Image Block & Button Block
- How to update mark-up of a gallery block in a custom theme?
- Auto focus RichText field
- How to create nested array attribute
- Show popover with url and option to open in new window
- How to Modify WP_Includes/blocks/latest_posts.php
- How to render block editor in wp-admin custom pages programmatically
- Social-Link block not loading html on page with custom theme
- How to diagnose wp-env environment problem
- Attribute form NumberControl doesn’t update when I update page before it lose its focus
- WP Gutenberg custom block – generate theme colors from SASS and use them in the inspector and php callback
- Posts Page shows Classic Editor interface not Gutenberg
- How can I include custom Gutenberg Blocks in a theme?
- Block validation failed for `core/pullquote` after adding theme support for editor-color-palette
- Is there a way to add classes to a page when using a Gutenberg reusable block as page layout?
- Correct way to make a custom block theme responsive
- Multiple content areas with Gutenberg – Transparent areas mid content
- Insert gutenberg blocks into template
- Template for posts of category in block theme?
- Can’t select my block by clicking on it on apiVersion – but using blockProps
- How can I use pre declared blocks in a php file?
- Is there any filter or action hook to remove layout classes from appearing in my templates?
- Full site editing templates folder vs block-templates
- How to set the margin on an innerBlock in a block variation?
- Align images to the left of the content
- Image and font support missing in editor when deploying theme remotely
- Why is my Toggle field not showing in Gutenberg?
- When trying to run build script with gutenberg (with SVG import) – Error: Plugin name should be specified
- Remove Gutenberg Buttons Block
- Block to show posts from same category
- Making update notification functionality for my themes
- Best practice for including plugins as part of a theme?
- Where do I find the functions triggered within a hook?
- Is it possible to display the admin bar while in the Theme Customizer?
- Pagination & get_pages?
- Easy WordPress theme creation tutorial? [closed]
- How do I add a post to a menu
- Demo Import changes terms ids
- how to change WordPress menu markup/classes
- How to get the URI to a theme without the domain. Example: /wp-content/themes/my-theme
- How to handle custom form submission?
- menu behavior is not as expected
- My custom theme does not load the translations
- How to add code in the content area in a WordPress theme?
- Can I show all the template files that are being used on my site?
- get_theme_mod returning no output
- Where to find the code that redirects requests on the static page URL to the home page
- How to change database values on theme update
- after renaming my wp-content folder, how do I upgrade my wordpress version?
- Issue on Adding A Class to Bootstrap Navbar Walker Dropdown
- Theme’s window.open call goes to “Page Not Found”
- Dynamic menu links after header title
- Does the textdomain have to be the theme’s name?
- Prerequisites Skills to learn WordPress [closed]
- How to rotate every letter in a title
- WordPress Theme that returns all posts as a JSON object?
- Use a filter on menu items that have children
- Reusable and site-wide content that can be used in a theme
- New to WordPress – Read the Codex, Other Docs; Still Confused
- Style first 3 posts differently with WP_Query [duplicate]
- is_front_page use in sidebar.php
- matisse theme show excerpts not whole content
- My custom taxonomies are not showing up in the admin menus
- How to add custom theme in hosting server?
- WordPress Custom Theme : Theme Builder vs ACF vs Gutenberg
- Debugging slow WordPress Theme Customizer (Any option similar to Query Monitor)?
- How to show children pages as array
- How do I keep images in posts below a certain size without editing the post?
- Is it possible to customize the layout of Gallery Shortcode?
- How can i use archive.php for indexing wordpress default posts?
- How can I add a single image from a gallery into the page header?
- How to set up a development/staging site to make major changes to the theme then update on the live site?
- What is the point of using the front-page.php template? [closed]