WP-ShowHide

Description

By default the content is hidden and user will have to click on the “Show Content” link to toggle it. Similar to what Engadget is doing for their press releases. Example usage: [showhide type="pressrelease"]Press Release goes in here.[/showhide]

Usage

  1. By default, content within the showhide shortcode will be hidden.
  2. Example: [showhide]Press release content goes in here.[/showhide]
  3. Default Values: [showhide type="pressrelease" more_text="Show Press Release (%s More Words)" less_text="Hide Press Release (%s Less Words)" hidden="yes"]

  4. You can have multiple showhide content within a post or a page, just by having a new type.

  5. Example: [showhide type="links" more_text="Show Links (%s More Words)" less_text="Hide Links (%s Less Words)"]Links will go in here.[/showhide]

  6. If you want to set the default visibility to display.

  7. Example: [showhide hidden="no"]Press release content goes in here.[/showhide]

  8. You can style the content via CSS that is generated by the plugin. Here is a sample of the generated HTML. Note that pressrelease is the default type.

<div id="pressrelease-link-1" class="sh-link pressrelease-link sh-hide">
  <button type="button" class="sh-toggle" aria-expanded="false" aria-controls="pressrelease-content-1"
          data-sh-more="Show Press Release (4 More Words)"
          data-sh-less="Hide Press Release (4 Less Words)">Show Press Release (4 More Words)</button>
</div>
<div id="pressrelease-content-1" class="sh-content pressrelease-content sh-hide" hidden>Content</div>
  1. With the example above, here are the following styles you can use in your CSS:
.sh-link { }  
.sh-toggle { }  
.sh-content { }  
.pressrelease-link { }  
.pressrelease-link.sh-hide .sh-toggle { }  
.pressrelease-link.sh-show .sh-toggle { }  
.pressrelease-content { }  
.pressrelease-content.sh-hide { }  
.pressrelease-content.sh-show { }

Development

https://github.com/lesterchan/wp-showhide

Credits

Donations

I spent most of my free time creating, updating, maintaining and supporting these plugins, if you really love my plugins and could spare me a couple of bucks, I will really appreciate it. If not feel free to use it without any obligations.

Breaking Changes

Version 2.0.0 rewrites the front-end JavaScript. The shortcode and its attributes are unchanged, so your posts do not need editing — but the generated HTML is different, so custom CSS and JavaScript may need updating.

  • The toggle is now a <button class="sh-toggle"> instead of <a href="#">. CSS targeting .sh-link A must become .sh-link .sh-toggle. The plugin ships a small inline style so the button still renders as a plain text link rather than a native button.
  • The inner <span id="{type}-toggle-{post_id}"> has been removed. The label now sits directly on the button, so anything targeting that ID should target .sh-toggle instead.
  • Hidden content now uses the hidden attribute instead of style="display: none;". If your CSS sets display on .sh-content it will now win over [hidden]; add .sh-content[hidden] { display: none; } or raise your specificity.
  • jQuery is no longer enqueued by this plugin. If your theme was relying on WP-ShowHide to pull jQuery onto the page, enqueue it yourself.
  • The global showhide_toggle() function has been removed. Nothing replaces it. To toggle a block programmatically, click its .sh-toggle button; to react to a toggle, listen for the sh-link:toggle event.
  • Internet Explorer is no longer supported. The script uses Element.closest() and the CustomEvent constructor.
  • Repeating the same type within one post now appends a counter to the element IDs (pressrelease-content-1, pressrelease-content-1-2, …). The first occurrence keeps its original ID, so this only affects posts that were previously emitting duplicate IDs anyway. Style by class rather than ID if you use this pattern.

The sh-link:more, sh-link:less and sh-link:toggle events are not a breaking change — they still fire on the .sh-link element and still bubble, so existing jQuery( ... ).on( 'sh-link:toggle', ... ) handlers keep working.

Screenshots

FAQ

N/A

Reviews

April 13, 2025
Thanks for the free plugin and support. it doesn’t work woth the latest wp. the hided side can not be seen after click the show. it is only active when logged in to wp-admin. please update it.
February 9, 2022
I don’t understand why developers take the time to write a plugin and then don’t bother to provide detailed documentation. Looks like it might do what I want but I give up trying and notice a lot of support requests have not been replied to.
January 30, 2021
Simple and working plugin. Tried several more, but they had issues with filter Im using on my page, this one worked like a charm. Additionally I would recommend to add an option to show hide button on the bottom of displayed text.
December 23, 2020 1 reply
Love this plugin. Had a little panic that it wasn’t going to work with Wordpress 5.6 and php 7.4, but it does. Please keep maintaining this plugin! (I just sent my donation.)
September 20, 2020
It’s a great idea and could be very useful but it doesn’t work on the current WP version. The site I was trying to use this on uses WP 5.5.1, with plugins Akismet, Feed Them Social, Feedzy, and Lightbox. I figure this plugin may be incompatible with one of those plugins or this current version of WP. The link doesn’t do anything when clicked and the wrong text is showing up. Even though I changed the shortcode to say ‘MORE INFO’ it still said Press Release along with the additional number text and a number next to it. I didn’t see settings anywhere for this plugin.
Read all 42 reviews

Contributors & Developers

“WP-ShowHide” is open source software. The following people have contributed to this plugin.

Contributors

“WP-ShowHide” has been translated into 4 locales. Thank you to the translators for their contributions.

Translate “WP-ShowHide” into your language.

Interested in development?

Browse the code, check out the SVN repository, or subscribe to the development log by RSS.

Changelog

2.0.0

  • New: WordPress 7.0
  • New: Rewritten in vanilla JavaScript, jQuery is no longer required
  • New: The JavaScript is now only loaded on pages that actually use the shortcode
  • New: The toggle is now a <button> with aria-controls, and its state is driven by aria-expanded
  • FIXED: Fatal error when the more_text/less_text attributes contain extra format specifiers
  • FIXED: Malformed JavaScript when the shortcode is used outside of the loop
  • FIXED: The type attribute is now restricted to characters that are valid in an HTML ID/class
  • FIXED: Word count now counts all whitespace, so multi-paragraph content is no longer under-counted
  • FIXED: PHP 8.1+ deprecation notice when the shortcode is used without any content
  • FIXED: The toggle label no longer desyncs when the more/less text contains a backslash
  • FIXED: Using the same type more than once in a post no longer produces duplicate element IDs
  • FIXED: Word count no longer counts the contents of <script> and <style> blocks as words
  • Removed: load_plugin_textdomain(), which WordPress has handled automatically since 4.6
  • Removed: The global showhide_toggle() function, superseded by the delegated click handler

1.06

  • FIXED: esc_html() for more text to prevent XSS

1.05

  • FIXED: esc_attr type attributes to prevent XSS

1.04

  • NEW: Added aria-hidden and aria-expanded to elements

1.03

  • NEW: Added .sh-link and .sh-content as a standard class name on top of the type specific class name.
  • NEW: Added do_shortcode() to allow shortcode to be parsed within ShowHide

1.02

  • FIXED: Some theme uses .hide as display: none and hence I have changed .show to .sh-show and .hide to .sh-hide to advoid conflicts.

1.01

  • NEW: Added additional show or hide class to the link and content depending on the visiblity of the content to allow more precise CSS styling.

1.00 (01-05-2011)

  • FIXED: Initial Release