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.
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.
Toggle effects help make your WordPress posts cleaner, user-friendly, and more dynamic by easily showing or hiding content.
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:
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.
If you implement the WordPress block editor (Gutenberg), certain blocks may allow you to add toggle or collapsible content without a plugin.
Steps:
If your editor lacks a toggle block, you can apply a plugin such as “Ultimate Addons for Gutenberg” or “Kadence Blocks.”
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>
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.
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.
Learn how to compress images in PowerPoint to reduce file size without losing quality. Discover simple steps to make your presentations lighter and more efficient.
Master uppercase formatting in Word, Excel, and other apps. Capitalize all letters for professional documents easily now.
Master uppercase formatting in Word, Excel, and other apps. Capitalize all letters for professional documents easily now.
Learn how to avoid demonetization on YouTube by understanding new content, ad policy, and review rules that affect earnings.
Learn how to bulk resize large WordPress images without losing quality using plugins like ShortPixel, EWWW, and TinyPNG.
Easy methods to limit WordPress Heartbeat API, boosting performance and cutting CPU usage without sacrificing core functionality.
Learn methods to efficiently separate text in Excel and Google Sheets for better data management.
How to use the picture-in-picture effect in iMovie to create engaging videos with overlays, ideal for tutorials, reactions, and more.
Discover how to use Claude Artifacts to quickly build and deploy powerful web applications in hours instead of weeks.
Learn how to effortlessly create a digital signature in Adobe with this easy-to-follow guide. Discover how to set up, use, and troubleshoot your digital signature using Adobe tools.
Want to improve your video framing? This guide walks you through cropping videos in Filmora with ease—perfect for removing distractions and tightening up your shots.
Learn advanced tips, use cases, and best practices to optimize your forms for better organization and dynamic user experiences.