mww2

Mastering the Toggle Effect in WordPress: A Comprehensive Guide

Do you want to make your WordPress posts look cleaner and more interactive? Adding a toggle effect in WordPress is a simple way to show or hide extra text without overwhelming your readers. This feature helps keep your content concise while offering full information when needed. It’s perfect for FAQs, long steps, or bonus content you don’t want visible all the time.

With just a click, visitors can open or close a section—making your page easier to explore. You don’t need to be a coding expert to use it. Whether you prefer plugins, the Gutenberg Block Editor, or a bit of simple code, there’s a method for everyone. In this guide, you’ll learn how to add this helpful effect to your WordPress posts—step by step.

Understanding the Toggle Effect

The toggle effect allows you to show or conceal items on your website with just one click. It operates via a button or clickable text. Click to reveal hidden text and click again to hide it. This feature gives your page a clean look and avoids clutter, allowing users to focus on the key ideas. It’s fantastic for steps, questions, or lengthy responses.

The toggle effect keeps your material simple and concise. Users can skip irrelevant sections and open only those they find interesting, reducing confusion and saving time. It also encourages users to explore your website longer without feeling overwhelmed. By hiding rather than deleting unnecessary information, your site remains tidy yet complete. Simple, practical, and effective, it enhances website usability.

Easy Methods to Add Toggle Effect in WordPress

Toggle effects help make your WordPress posts cleaner, user-friendly, and more dynamic by easily showing or hiding content.

Method 1: Using a Plugin for Toggle Effect

The easiest approach to achieving the toggle effect using plugin options is to use a WordPress plugin. You do not need to write any code. Many plugins offer accordion or toggle functionality.

Steps to Use a Plugin:

  1. Go to your WordPress dashboard.
  2. Click Plugins > Add New.
  3. Search for “Toggle” or “Accordion” plugins.
  4. Choose a popular one like “Accordion by PickPlugins” or “Shortcodes Ultimate.”
  5. Install and activate the plugin.
  6. Go to the plugin settings if needed.
  7. Create toggle content inside your post or page using shortcodes or blocks.

Example Using “Shortcodes Ultimate”:

[su_toggle title="Click to show/hide text"]
This is the hidden content.
[/su_toggle]

When visitors click the title, the hidden content appears or disappears. This method is simple and fast. You can customize the toggle style in plugin settings.

Method 2: Using the Gutenberg Block Editor

If you implement the WordPress block editor (Gutenberg), certain blocks may allow you to add toggle or collapsible content without a plugin.

Steps:

  1. Open your post in the Gutenberg editor.
  2. Press the + button to add a block.
  3. Search for the “Toggle” or “Collapse” block.
  4. If your theme or block collection includes it, select it.
  5. Add the text you want to show and hide inside the block.
  6. Save and preview your post.

If your editor lacks a toggle block, you can apply a plugin such as “Ultimate Addons for Gutenberg” or “Kadence Blocks.”

Method 3: Adding Toggle Effect Using HTML, CSS, and JavaScript

For those seeking more control, creating your toggle effect with code is an option. It’s ideal for custom themes or avoiding plugins.

Step 1: Add HTML to Your Post

Switch your WordPress editor to HTML mode and add this code where you want the toggle:

<button class="toggle-btn">Show More</button>
<div class="toggle-content" style="display:none;">
  <p>This is the hidden text that will appear when clicked.</p>
</div>

Step 2: Add CSS for Style

Add this CSS to the Customizer’s Additional CSS part or the stylesheet of your theme:

.toggle-btn {
  background-color: #0073aa;
  color: white;
  border: none;
  padding: 8px 12px;
  cursor: pointer;
  border-radius: 4px;
}

.toggle-content {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
}

Step 3: Add JavaScript to Handle the Toggle

You can add this JavaScript inside a code block or in your theme’s footer script:

<script>
document.addEventListener('DOMContentLoaded', function() {
  const toggleBtn = document.querySelector('.toggle-btn');
  const toggleContent = document.querySelector('.toggle-content');
  toggleBtn.addEventListener('click', function() {
    if (toggleContent.style.display === 'none') {
      toggleContent.style.display = 'block';
      toggleBtn.textContent = 'Show Less';
    } else {
      toggleContent.style.display = 'none';
      toggleBtn.textContent = 'Show More';
    }
  });
});
</script>

Method 4: Using WordPress Shortcodes for Toggle

In WordPress, you can design your toggling shortcode under PHP functions. It is for those who are comfortable altering code.

Step 1: Add this PHP Code to Your Theme’s Functions.php File:

function custom_toggle_shortcode($atts, $content = null) {
  return '<button class="custom-toggle-btn">Show More</button>
    <div class="custom-toggle-content" style="display:none;">' . do_shortcode($content) . '</div>
    <script>
    document.addEventListener("DOMContentLoaded", function() {
      const btn = document.querySelector(".custom-toggle-btn");
      const content = document.querySelector(".custom-toggle-content");
      btn.addEventListener("click", function() {
        if(content.style.display === "none") {
          content.style.display = "block";
          btn.textContent = "Show Less";
        } else {
          content.style.display = "none";
          btn.textContent = "Show More";
        }
      });
    });
    </script>';
}
add_shortcode('toggle', 'custom_toggle_shortcode');

Step 2: Use the Shortcode in Your Post:

[toggle]Your hidden content here[/toggle]

This shortcode adds a toggle button automatically.

Conclusion

Adding the toggle effect is a straightforward way to enhance your WordPress content. It keeps your posts neat, readable, and user-friendly. Users can access just the information they choose, improving page load times and conserving space, especially on mobile devices. You can apply this effect with plugins, blocks, shortcodes, or basic code. No advanced knowledge is required. Your site becomes more dynamic and user-friendly in just a few steps. Try one of these techniques today to see the difference it makes. Your guests will appreciate the improved experience and cleaner, smarter layout.