WP-ShowHide

Descripción

WP-ShowHide hides part of a post behind a button, so something long — a press release, a changelog, a spoiler — does not fill the page until a reader asks for it. The button says how many words it is hiding, which is what Engadget does with their press releases. Example usage: [showhide type="pressrelease"]Press Release goes in here.[/showhide]

There is nothing to configure and no settings screen. Every choice the plugin offers is an attribute of the shortcode that makes it, so two toggles in the same post can behave differently.

Features

  • One shortcode, [showhide], usable any number of times in a post or page
  • A Show/Hide block for the block editor, holding the content it hides as ordinary blocks and rendering exactly what the shortcode renders
  • A button rather than a link, with aria-expanded and aria-controls, so the toggle works from the keyboard and reads correctly to a screen reader
  • Labels that count the words they are hiding
  • No jQuery, and no script at all on a page that uses neither the shortcode nor the block
  • Custom DOM events on every toggle, for themes that want to react to one

Donaciones

Paso la mayor parte de mi tiempo libre creando, actualizando, manteniendo y dando soporte para mis plugins. Si realmente te encantan mis plugins y podrías ahorrarme un par de dólares, realmente lo agradeceré. Si no, se libre de usarlos sin ninguna obligación.

Uso

  1. Por defecto, el contenido entre los shortcodes «showhide» está oculto.
  2. Ejemplo: [showhide]El contenido de la nota de prensa va aquí.[/showhide]
  3. Valores por defecto: [showhide type="pressrelease" more_text="Mostrar nota de prensa (%s palabras más)" less_text="Ocultar nota de prensa (%s palabras menos)" hidden="yes"]

  4. Puedes tener múltiples contenidos de tipo «showhide» en una entrada o página, únicamente asignando «type» diferentes.

  5. Ejemplo: [showhide type="links" more_text="Mostrar enlaces (%s palabras más)" less_text="Ocultar enlaces (%s palabras menos)"]Los enlaces irán aquí.[/showhide]

  6. Si quieres establecer la visibilidad predeterminada que mostrar.

  7. Ejemplo: [showhide hidden="no"]El contenido de la nota de prensa va aquí.[/showhide]

Block editor

There is a Show/Hide block too, filed under Text in the inserter. It holds the content it hides as ordinary blocks — paragraphs, images, anything — so that content is written and edited in place instead of being typed into a field as markup, and it stays visible while you are editing. The Show/Hide panel in the sidebar carries the same four choices the shortcode attributes carry: the type, the two button labels, and whether it starts hidden.

The shortcode is unchanged and still supported. It is not deprecated, posts that use it need no editing, the block and the shortcode render the same markup, and one post can hold both.

  1. Puedes dar estilo al contenido mediante CSS que es generado por el plugin. Aquí hay una muestra del HTML generado. Ten en cuenta que «pressrelease» es el «type» por defecto.
<div id="pressrelease-link-1" class="wp-showhide 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="wp-showhide sh-content pressrelease-content sh-hide" hidden>Content</div>
  1. Con el ejemplo de arriba, aquí están algunos estilos que puedes usar en tu 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 { }
  1. Every toggle fires three events on the .sh-link element, and all three bubble, so one listener on the document covers every toggle on the page: sh-link:more when a toggle opens, sh-link:less when it closes, and sh-link:toggle on both.

Capturas

Bloques

Este plugin proporciona 1 bloque.

  • Show/Hide Hides its content behind a button that counts the words it is hiding.

Instalación

  1. Install and activate the plugin.
  2. Wrap the content you want hidden in [showhide] and [/showhide], or add the Show/Hide block in the editor and put the content inside it.

There is nothing to configure and no settings screen. Every choice the plugin offers is an attribute of the shortcode or a control in the block’s sidebar, so two toggles in the same post can behave differently.

FAQ

How do I change the button text?

Pass more_text and less_text on the shortcode. %s in either one is replaced with the number of words being hidden, and a label with no %s in it is used exactly as written.

Can I drop the plugin’s stylesheet?

Yes. It is two rules and it is enqueued under the handle wp-showhide, so dequeue it from your theme:

add_action( 'wp_enqueue_scripts', function () {
    wp_dequeue_style( 'wp-showhide' );
}, 20 );

The toggle keeps working; the button will simply look like your theme’s buttons instead of like a text link.

Why did the same type give me duplicate IDs?

It no longer does. Since 2.0.0 the first toggle of a given type in a post keeps the ID it has always had and later ones are suffixed -2, -3 and so on. Style by class rather than by ID if you use the same type more than once.

Does the plugin store anything in my database?

One row, and it is tiny. wp_showhide_version records the version last run so that an upgrade knows what it is upgrading from. There is no settings row, because there are no settings. Deleting the plugin from the Plugins screen removes the row, on a single site and on every site of a network.

Reseñas

13 de abril de 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.
9 de febrero de 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.
30 de enero de 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.
23 de diciembre de 2020 1 respuesta
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.)
20 de septiembre de 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.
Leer todas las 42 reseñas

Colaboradores y desarrolladores

«WP-ShowHide» es un software de código abierto. Las siguientes personas han colaborado con este plugin.

Colaboradores

«WP-ShowHide» está traducido en 5 idiomas. Gracias a los traductores por sus contribuciones.

Traduce «WP-ShowHide» a tu idioma.

¿Interesado en el desarrollo?

Revisa el código , echa un vistazo al repositorio SVN o suscríbete al registro de desarrollo por RSS.

Registro de cambios

3.0.0

  • BREAKING: Requires WordPress 6.8 and PHP 8.2, up from 6.0 and 7.4.
  • BREAKING: Removed the showhide_scripts(), showhide_js() and showhide_shortcode() global functions. They were internals; the plugin registers its own shortcode and assets.
  • BREAKING: The ShowHide and ShowHide_Template classes are now WP_ShowHide and WP_ShowHide_Template.
  • NEW: Added a Show/Hide block for the block editor, which holds the content it hides as ordinary blocks. The [showhide] shortcode is unchanged and still supported — it is not deprecated, posts using it need no editing, and the two render the same markup.
  • NEW: Restructured into includes/, behind the WP_ShowHide, WP_ShowHide_Template and WP_ShowHide_Options classes.
  • NEW: Added the wp_showhide_version row, and an uninstall.php that deletes it on a single site and across a network.
  • NEW: The toggle script and the stylesheet are now files, js/wp-showhide.js and css/wp-showhide.css, so a browser caches them once instead of reading them inline on every page.
  • NEW: Added a PHPUnit and vitest test suite, and GitHub Actions CI.
  • CHANGED: Both elements the shortcode renders now carry a wp-showhide class alongside the classes they have always had. Nothing was renamed or removed, so existing theme CSS is unaffected.
  • FIXED: hidden="No" left the content collapsed instead of expanding it. The attribute is matched case insensitively now, so any spelling of no works.
  • FIXED: Requesting wp-showhide.php directly ran it outside WordPress instead of exiting.