Articoolo
  • Home
  • Content Marketing
  • Digital Strategy
  • AI Tools
  • About
  • Contact Us
No Result
View All Result
Articoolo
No Result
View All Result
Advertisement Banner
Home Latest Updates

How to Build Custom Toolbar Buttons That Insert Dynamic Content Blocks

by Judy Hernandez
2025/10/31
in Latest Updates
386 12
How to Build Custom Toolbar Buttons That Insert Dynamic Content Blocks

Have you ever wanted to add your own custom button to your WYSIWYG editor that instantly inserts your favourite content template?

Maybe a styled callout box, a testimonial card, or a formatted code snippet, whatever you use often. Custom toolbar buttons save you tons of time and help keep your content consistent and clean.

In this guide, I’ll show you how to create custom toolbar buttons in JavaScript-based WYSIWYG editors. I’ll be using Froala Editor’s API for the examples since it makes the process straightforward, but the same idea works in most WYSIWYG editors.

By the end, you’ll be able to add your own custom buttons that insert nicely formatted content blocks with just a single click.

pic.twitter.com/8jUHELm2nv

— Evan (@itsEvanCC) October 19, 2025

Key Takeaways

  • Custom toolbar buttons let you insert reusable content templates with just one click.
  • Froala’s custom button API makes it very easy to extend the editor’s functionality.
  • You can insert HTML content dynamically using the editor’s insertion methods.
  • Custom buttons help you work faster and keep your content design consistent.
  • You only need basic JavaScript to build these, nothing too advanced.

Now that you know what we’ll be covering, let’s start with the basics: what exactly are custom toolbar buttons?

Table of Contents

Toggle
  • What Are Custom Toolbar Buttons?
  • Setting Up Your Editor
  • Creating a Simple Callout Button
  • Creating a Testimonial Card Button
  • Code Snippet Container
  • Best Practices for Creating Custom Buttons
  • Common Pitfalls to Avoid
  • Conclusion
  • About the Author

What Are Custom Toolbar Buttons?

Custom toolbar buttons are basically extra buttons you can add to your editor that do exactly what you need.

Instead of typing or pasting the same HTML again and again, you just click a button and it appears automatically.

Think of them as shortcuts for your most-used content blocks, like:

  • Alert boxes or callouts
  • Testimonial cards
  • Code snippet containers
  • Custom layouts
  • Styled information boxes

So now that you know what these buttons do, let’s go ahead and start creating them.

Setting Up Your Editor

Before creating custom buttons, you’ll need a basic Froala Editor setup. Here’s the simplest way to get started:

<!DOCTYPE html>
<html>
  <head>
    <meta charset=”utf-8″ />
    <title>Custom Toolbar Buttons</title>

    <!– Froala CSS –>
    <link
      href=”<https://cdn.jsdelivr.net/npm/froala-editor@latest/css/froala_editor.pkgd.min.css>”
      rel=”stylesheet”
    />
  </head>
  <body>
    <div id=”editor”></div>

    <!– Froala JS –>
    <script src=”<https://cdn.jsdelivr.net/npm/froala-editor@latest/js/froala_editor.pkgd.min.js>”></script>

    <script>
      // Initialize the editor
      new FroalaEditor(“#editor”);
    </script>
  </body>
</html>

This gives you a basic editor with all the standard formatting buttons. Now let’s add our custom buttons to it.

Creating a Simple Callout Button

Let’s create a button that inserts a styled callout box. It’s perfect for highlighting important information.

<script>
  // Define a custom button icon for the editor toolbar
FroalaEditor.DefineIcon(“insertCallout”, {
  NAME: “💡”, // The emoji that will appear on the button
  template: “text”, // Use text-based icon
});

// Register the custom button and define its behavior
FroalaEditor.RegisterCommand(“insertCallout”, {
  title: “Insert Callout”, // Tooltip text when hovering over the button
  focus: true, // Keep the editor focused after clicking
  undo: true, // Enable undo for this action
  refreshAfterCallback: true, // Refresh toolbar after insertion
 
// Function that runs when the button is clicked
  callback: function () {
    // HTML content to insert into the editor
    var calloutHTML = `
      <div style=”background-color: #e3f2fd; border-left: 4px solid #2196f3; padding: 15px; margin: 15px 0; border-radius: 4px;”>
        <strong>💡 Important:</strong> Add your message here
      </div>
      <p><br></p>
    `;
    // Insert the HTML content at the current cursor position
    this.html.insert(calloutHTML);
  },
});

// Initialize the Froala Editor and include the custom button in the toolbar
new FroalaEditor(“#editor”, {
  toolbarButtons: [“bold”, “italic”, “|”, “insertCallout”],
});
</script>

What this code does:

  1. DefineIcon creates the button’s visual appearance (💡 here).
  2. RegisterCommand defines what happens when the button is clicked.
  3. callback function contains the logic for inserting the callout box.
  4. this.html.insert() adds the HTML at the cursor position.
  5. Initialising FroalaEditor with the button adds it to the toolbar alongside default formatting options.

Creating a Testimonial Card Button

Now, let’s create a testimonial card with a quote, the author, and their company.

<script>
  // Define a custom button icon for the editor toolbar
FroalaEditor.DefineIcon(“insertTestimonial”, {
  NAME: “💬”, // The emoji that appears on the button
  template: “text”, // Use a text-based icon
});

// Register the custom button and define its behavior
FroalaEditor.RegisterCommand(“insertTestimonial”, {
  title: “Insert Testimonial”, // Tooltip text on hover
  focus: true,  // Keep editor focused after click
  undo: true, // Enable undo for this action
  refreshAfterCallback: true, // Refresh toolbar after insertion

// Function that runs when the button is clicked
  callback: function () {
    // HTML content for the testimonial card
    var testimonialHTML = `
      <div style=”background-color: #f9f9f9; border: 1px solid #ddd; padding: 20px; margin: 20px 0; border-radius: 8px;”>
        <p style=”font-style: italic; font-size: 16px; margin: 0 0 15px 0;”>
          “This is an amazing product! It has completely transformed how we work.”
        </p>
        <div style=”display: flex; align-items: center; gap: 10px;”>
            <div style=”width: 50px; height: 50px; background-color: #ccc; border-radius: 50%;”>  <img src=”<https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTpnd63pzTs_uaC9d2Kf8Fds5eDXPFn29fWVQ&s>” alt=”John Doe” style=”width: 50px; height: 50px; border-radius: 50%;”></div>
          <div>
            <strong>John Doe</strong><br>
            <span style=”color: #666; font-size: 14px;”>CEO, Company Name</span>
          </div>
        </div>
      </div>
      <p><br></p>
    `;
    // Insert the testimonial card HTML at the current cursor position
    this.html.insert(testimonialHTML);
  },
});

// Initialize the Froala Editor with the custom button added to the toolbar
new FroalaEditor(“#editor”, {
  toolbarButtons: [“bold”, “italic”, “|”, “insertTestimonial”],
});
</script>

What this code does:

  1. DefineIcon creates a custom toolbar button with a 💬emoji.
  2. RegisterCommand sets what happens when the button is clicked.
  3. callback contains the logic for inserting a testimonial card.
  4. this.html.insert() adds the testimonial HTML at the current cursor position.
  5. Initialising FroalaEditor with toolbarButtons adds the custom button to the editor toolbar.
  6. Users can click the button and then customise the placeholder text with their actual testimonial content.

Code Snippet Container

If you’re creating technical docs, a button to insert code snippets can be a real time-saver:

<script>
  // Define a custom button icon for the Froala toolbar
FroalaEditor.DefineIcon(“insertCode”, {
  NAME: “codeView”, // Icon name (built-in Froala icon)
  SVG_KEY: “codeView”, // The SVG used for the icon
});

// Register the custom button and define its behavior
FroalaEditor.RegisterCommand(“insertCode”, {
  title: “Insert Code Block”, // Tooltip text when hovering over the button
  focus: true,  // Keep editor focused after clicking
  undo: true, // Enable undo for this action
  refreshAfterCallback: true, // Refresh toolbar after insertion

  // Function executed when the button is clicked
  callback: function () {
    // HTML content for the code block
    var codeHTML = `
      <div style=”background-color: #282c34; color: #abb2bf; padding: 20px; margin: 15px 0; border-radius: 6px; font-family: ‘Courier New’, monospace; overflow-x: auto;”>
        <div style=”color: #888; font-size: 12px; margin-bottom: 10px;”>JavaScript</div>
        <pre style=”margin: 0; color: #abb2bf;”><code>function greet(name) {
  console.log(‘Hello, ‘ + name + ‘!’);
}

greet(‘World’);</code></pre>
      </div>
      <p><br></p>
    `;
   
    // Insert the code block at the current cursor position
    this.html.insert(codeHTML);
  },
});

// Initialize Froala Editor and include the custom button in the toolbar
new FroalaEditor(“#editor”, {
  toolbarButtons: [“bold”, “italic”, “|”, “insertCode”],
});
</script>

What this code does:

  1. DefineIcon creates a custom toolbar button using Froala’s built-in codeView icon.
  2. RegisterCommand sets what happens when the button is clicked.
  3. callback contains the logic to insert a styled code block with a language label and sample code.
  4. this.html.insert() inserts the code block HTML at the current cursor position.
  5. Initialising FroalaEditor with toolbarButtons adds the custom Insert Code Block button to the editor.
  6. Clicking the button creates a dark-themed code block that looks professional and is easy to read.

Best Practices for Creating Custom Buttons

Creating custom buttons isn’t just about adding features, it’s about making the editor easier to use. These tips will help you build buttons that work well and are easy for users to use.

  • Keep HTML simple: Use basic inline styles rather than complex CSS classes. This ensures your content looks consistent even if you copy it to other platforms. For more tips, check out practices for WYSIWYG editors.
  • Add breathing room: Always add a paragraph break (<p><br></p>) after your inserted content so users can easily keep typing.
  • Use semantic HTML: Inline styles are fine for quick templates, but using proper HTML structure makes your content more meaningful and easier to maintain:
<aside class=”callout”>
  <strong>Note:</strong> Your content here
</aside>
  • Make content editable: Make sure anything you insert can be easily changed. Avoid deeply nested structures that are hard to edit.
  • Test undo/redo: Using undo: true option in your button setup lets users easily undo the insertion if needed.
  • Provide clear icons: Use icons that clearly show what the button does. Froala has lots of built-in SVG icons you can choose from.

Common Pitfalls to Avoid

Even small mistakes can make custom buttons harder to use or maintain. Here are a few common issues to watch out for when building and testing your buttons.

  • Forgetting the callback context: Always use this.html.insert() inside the callback. Here, this points to the editor instance.
  • Overly complex HTML: Avoid complex nested divs, they’re tricky to edit and maintain. For advanced layouts, use the editor’s built-in tools.
  • Test on mobile: Make sure your buttons and inserted content work well on mobile devices.
  • Forgetting toolbar configuration: Remember to add your custom button to the toolbarButtons array, or it won’t show up.

Conclusion

Creating custom toolbar buttons in your WYSIWYG editor is easier than you might think. With just a few lines of JavaScript, you can add buttons that insert nicely formatted content blocks with a single click.

We’ve covered three examples: callouts, testimonials, and code snippets, but you can make buttons for almost anything, like:

  • Pricing tables
  • FAQ sections
  • Image galleries
  • Custom forms
  • Product showcases

If you want more inspiration, check out Froala’s examples.

The key is to start simple, test your buttons, and add more features as you get comfortable with the API. It will save you lots of time and keep your content looking consistent.

About the Author

Shefali Jangid is a web developer, technical writer, and content creator passionate about building intuitive developer tools and educational resources. She shares tutorials, code snippets, and practical tips on her blog, shefali.dev, helping developers create better web experiences with clean, efficient, and accessible code.

Advertisement Banner

Related Posts

Online Table Games: How Digital Platforms Can Preserve Classic Pastimes for Modern Audiences
Latest Updates

Online Table Games: How Digital Platforms Can Preserve Classic Pastimes for Modern Audiences

by Judy Hernandez
February 11, 2026
0

Table games have existed for centuries and were rooted in not just the social aspect but also mathematics and decision-making. Games like blackjack,...

Read moreDetails
Why Finland Could Be the Perfect Test Market for VR Entertainment
Latest Updates

Why Finland Could Be the Perfect Test Market for VR Entertainment

by Judy Hernandez
February 9, 2026
0

Virtual reality has spent years hovering at the edge of mainstream adoption, promising transformation while often delivering novelty. Yet certain markets offer...

Read moreDetails
The Crash Games on the 1xBet Website
Latest Updates

The Crash Games on the 1xBet Website

by Judy Hernandez
February 5, 2026
0

Crash games occupy a separate segment in the world of online casinos — dynamic gambling entertainment that is distinguished by simple rules...

Read moreDetails
Instant PayID Withdrawal Casino Australia And Fast Payment Features
Latest Updates

Instant PayID Withdrawal Casino Australia And Fast Payment Features

by Judy Hernandez
February 5, 2026
0

Ever felt like getting your money online should feel as quick as sending a message on your phone?  Many players today prefer...

Read moreDetails
How Live Casino Games Are Being Used Online in Ontario
Latest Updates

How Live Casino Games Are Being Used Online in Ontario

by Judy Hernandez
February 5, 2026
0

Live casino games are a way that allows you to relax by bringing the thrill of real casinos directly to your screen....

Read moreDetails
6 Inspiring Layout Ideas You Can Create With Lyric Video Maker Online
Latest Updates

6 Inspiring Layout Ideas You Can Create With Lyric Video Maker Online

by Judy Hernandez
February 4, 2026
0

The process of making lyric videos is not always as easy as it sounds. You might have the song prepared, the lyrics...

Read moreDetails

Discussion about this post

Trending

PayID Pokies Online Australia: Fast Banking Meets Top Slot Games
General news

PayID Pokies Online Australia: Fast Banking Meets Top Slot Games

2 months ago
Mycelium And Mental Health: How Psilocybin Is Changing Therapy
General news

Mycelium And Mental Health: How Psilocybin Is Changing Therapy

5 months ago
Effective Techniques to Win at Live Casino Games Today
Latest Updates

Effective Techniques to Win at Live Casino Games Today

2 weeks ago
Articoolo

Recent News

Free AI Checker: How to Detect AI-Written Text in Seconds

Free AI Checker: How to Detect AI-Written Text in Seconds

February 10, 2026
Websites are Rapidly Increasing their Use of Long-Form Content

Websites are Rapidly Increasing their Use of Long-Form Content

February 9, 2026

Quick Links

  • Home
  • Privacy Policy
  • Terms & Conditions
  • About
  • Contact Us

© 2026 Articoolo. All Rights Reserved
607 Cloverwisp Ln, West Marrowbay, NH 03494

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
No Result
View All Result
  • Home
  • Content Marketing
  • Digital Strategy
  • AI Tools
  • About
  • Contact Us

© 2026 Articoolo. All Rights Reserved
607 Cloverwisp Ln, West Marrowbay, NH 03494