Welcome to Dagon Design. In addition to free scripts, WordPress plugins, and articles, we offer a variety of services including custom theme design, plugin creation, and PHP scripting. Contact me for more information.

Version 1.1   Updated Thursday, October 9th, 2008 at 7:19pm

Expanding Text plugin for WordPress

This WordPress plugin allows you to create sections of text in your post or page which expand/collapse when clicked on. You simply wrap the special tags around your text, and set the ‘expand link’ (the link visitors click on to show the text). If your visitors do not have javascript enabled, the ‘expand link’ is not shown, and the text is displayed normally.

Download

Change Log

  • 10-09-08 Version 1.1 - Now works properly when the exact same expanding text is used more than once on the page.
  • 08-14-08 Version 1.0 - First release.

Installing

  • Download the above file, rename it from .txt to .php, and upload it to your plugins directory.
  • Enable the plugin.
  • Optional: Add the CSS to your theme’s style sheet to make it look nice (see the customization section below).

Usage

To make your text expand/collapse, use the following format in your post or page:

Important: Make sure you add this using the html/code editor in WordPress, not the visual editor. In new versions of WordPress, just click the ‘html’ button above the edit box. If you use the visual editor it will not work, as the actual code you entered will be seen on the page, instead of being processed by the script.

<DDET (expand link text)>
(Text to expand)
</DDET>

Example:

<DDET Click to expand!>
Here is your text!
</DDET>

You can add as many sections of expanding text as you like.

Demo

Here you can see the plugin in action:

Here is your text! Here is your text! Here is your text! Here is your text! Here is your text! Here is your text! Here is your text! Here is your text! Here is your text! Here is your text! Here is your text! Here is your text! Here is your text! Here is your text! Here is your text! Here is your text! Here is your text! Here is your text! Here is your text! Here is your text!

Customization

To style the expanding text boxes, you must add the .ddet_div class to your theme’s style sheet. Here is an example:

.ddet_div {
  margin: 8px 0 0 12px;
  padding: 8px;
  background: #F4F4F4;
  border: 1px solid #DDDDDD;
}

Pages: [3] 2 1 » Show All

  1. 44
    Willow

    PS should have said, thanks! I love this plug in!

  2. 43
    Willow

    Does this plugin not work on Wp 2.6.5? I have 2 blogs on the same server (different subdomains) using the same theme, and the only difference is that one is on WP 2.6.3 and the other on 2.6.5. Expanding text doesn’t work on the latter. Is it just me?

  3. Nice plugin, i am using it now.

  4. 41
    Axeile

    Hi there, is there a way to change the window status message on mouseover? I tried adding onMouseover=”window.status=’click me’;return true;” into the php under $new_string but it returns a fatal error. I’ve also tried adding the onmouseover directly into the post but it didn’t work either. Currently javascript:expand(document.getElementByID(’blahblah’)) appears in the status bar upon mouseover on the “click to expand” link.

  5. Nice plugin!! Thank you for sharing

  6. Love it, but please please answer the question that’s been posted twice: how to avoid loosing the tags, including ones own text, when you swap between html and visual modes. Can we hack the visual editor?! I don’t mind adding the tags in html, but would like to still be able to edit the page in visual mode. Thanks;)

  7. Do you think this would work well built into a theme?

    Cheers!

  8. Allow me to rephrase…

    
    <ddet &#11024; Expand &#9585; Collapse &#11023;>
    </ddet>
    

    <ddet ⬐ Expand ╱ Collapse ⬏>
    <╱ddet>

  9. I love this! I have been wondering about this for some time. And I am hooked, baby!

    Now, if we could only use little buttons instead of text ….

    
    &lt;ddet &#11024; Expand &#9585; Collapse &#11023;&gt;
    &lt;&#9585;ddet&gt;
    

  10. 35
    Pete Lingo

    This is almost a superb plugin. I’m using it on WP2.6.2 and it works fine, except for a small problem. In the Write Post screen, if you switch from HTML mode to Visual Mode to check the content and then switch back, the snippets have all disappeared. Infuriating. :-(

  11. 34
    Mark

    I would also like to insert this code into a php template file to show/hide comments. Is there a way that this can be done with your plugin?

  12. Hmm, first I was more than happy to find that plugin — but after running W3C Markup Validation I changed to “I should wait until it is 100% valid” state. Maybe you should have a look at the validation errors and try to fix them. I would be very sorry not to use your very useful plugin.

  13. Pierre: To use this plugin, you just add that text directly into your post or page (make sure you are using the code, not visual, editor in WordPress) - not the template files.

  14. Hello. Very nice plugin.
    I’m trying to put it directly in a template, for showing the excerpt of the post in collapsed mode, and the whole content in plain mode.
    But the code above seems not to be recognized :

    
    <?php the_excerpt(); ?>
    	<DDET Click to expand!>
    <?php the_content(); ?>
    </DDET>
    

    Got an idea ? Thanks

Pages: [3] 2 1 » Show All

Leave a Comment

Before you comment: If you are having an issue with a script, please make sure you have read the entire article. Also, please read through the comments because most common issues have already been discussed many times. Thanks.


Be sure to wrap all code in <code></code> tags.