This plugin hasn’t been tested with the latest 3 major releases of WordPress. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress.

Accordion Shortcodes


Accordion Shortcodes is a simple plugin that adds a few shortcodes for adding accordion drop-downs to your pages.

The accordions should blend seamlessly with your theme. However, you may want to edit your theme’s main stylesheet in order to add some custom styling (see below for sample CSS).


  • Adds two shortcodes for adding accordions to your site
  • Supports multiple accordions with individual settings on a single page
  • Two buttons in the TinyMCE editor make it easy to add and configure the accordion shortcodes
  • Responsive
  • No default CSS added
  • Only adds JavaScript on pages that use the shortcodes
  • Support for item IDs and direct links
  • Accessible (for users requiring tabbed keyboard navigation control)

Optional Features

  • Open the first accordion item by default
  • Open all accordion items by default
  • Disable auto closing of accordion items
  • Manually close items by clicking the title again
  • Scroll page to title when it’s clicked open
  • Set the HTML tag for the title element
  • Change the semantic structure of your accordions (advanced)

The Shortcodes

The two shortcodes that are added are:



[accordion-item title=""]...[/accordion-item]

Basic Usage Example

[accordion-item title="Title of accordion item"]Drop-down content goes here.[/accordion-item]
[accordion-item title="Second accordion item"]Drop-down content goes here.[/accordion-item]

This will output the following HTML:

<div class="accordion">
    <h3 class="accordion-title">Title of accordion item</h3>
    <div class="accordion-content">
        Drop-down content goes here.
    <h3 class="accordion-title">Second accordion item</h3>
    <div class="accordion-content">
        Drop-down content goes here.

Sample CSS

Here is some sample CSS to get you started if you want to customize the look and feel of the accordion.

/* Accordion Styles */
.accordion {
    border-bottom: 1px solid #dbdbdb;
    margin-bottom: 20px;
.accordion-title {
    border-top: 1px solid #dbdbdb;
    margin: 0;
    padding: 20px 0;
    cursor: pointer;
.accordion-title:hover {}
.accordion-title:first-child {border: none;} {cursor: default;}
.accordion-content {padding-bottom: 20px;}

Opening an Accordion Via ID

You can optionally add a unique ID to each of your accordion items and then use that ID in the URL to open that item by default. For example, say you have the following accordions:

[accordion-item id="item-1" title="Title of accordion item"]Drop-down content goes here.[/accordion-item]
[accordion-item id="item-2" title="Second accordion item"]Drop-down content goes here.[/accordion-item]
[accordion-item id="item-3" title="A Third accordion"]Drop-down content goes here.[/accordion-item]

You could use this URL to open the third item by default:

All you need to do is ensure that the part after the # in the URL matches the ID set on the accordion item.

Advanced Accordion Settings

There are a few advanced settings you can add to the opening accordion shortcode. The full shortcode, with all the default settings looks like this:

[accordion autoclose="true" openfirst="false" openall="false" clicktoclose="false"]

autoclose: Sets whether accordion items close automatically when you open the next item. Set autoclose="true/false" on the opening accordion shortcode like this: [accordion autoclose="false"]. Default is true.

openfirst: Sets whether the first accordion item is open by default. This setting will be overridden if openall is set to true. Set openfirst="true/false" on the opening accordion shortcode like this: [accordion openfirst="true"]. Default is false.

openall: Sets whether all accordion items are open by default. It is recommended that this setting be used with clicktoclose. Set openall="true/false" on the opening accordion shortcode like this: [accordion openall="true"]. Default is false.

clicktoclose: Sets whether clicking an open title closes it. Set clicktoclose="true/false" on the opening accordion shortcode like this: [accordion clicktoclose="true"]. Default is false.

scroll: Sets whether to scroll to the title when it’s clicked open. This is useful if you have a lot of content within your accordion items. Set scroll="true/false" on the opening accordion shortcode like this: [accordion scroll="true"]. Default is false. You may also specify an integer for a pixel offset if you’d like the page to scroll further (useful when the site uses a fixed position header navigation). NOTE: Only use pixel offset integers of > 0. If you do not want a scroll offset, but still want scrolling, simply use scroll="true".

class: Sets a custom CSS class for the accordion group or individual accordion items. Set class="your-class-name" on the opening accordion or accordion-item shortcode like this: [accordion class="your-class-name"] or [accordion-item class="your-class-name"]. Added a class to the accordion-item will add the class to the title HTML tag.

tag: Set the global HTML tag to use for all accordion titles. Set tag="h2" on the opening accordion shortcode like this: [accordion tag="h2"]. Default is h3.

semantics: You can change the entire semantic structure of the accordions to use a definition list (dl, dt, dd) by setting semantics="dl" on the opening accordion shortcode like this: [accordion semantics="dl"]. By default the accordion will use div tags for the wrapper and content containers. If you set this option to dl, it is recommended that you do not also use the tag option. This feature is not selectable from the accordion button dialog box and must be added manually.

Advanced Accordion Item Settings

state: Sets the initial state of the accordion item to open or closed. Set state=open or state=closed on the opening accordion item shortcode like this: [accordion-item state=open]. This setting will override all other accordion settings except when linking to an accordion item via ID.

tag: You can also set the HTML tag for the titles of each accordion item individually by adding tag="tagname" to each [accordion-item] shortcode. Make sure to not include the angle brackets around the tag name. Example: to use <h2> instead of the default <h3> tag: [accordion-item title="Item title" tag="h2"]Item content[/accordion-item]. Using a tag attribute on an individual accordion item will override the global setting. The list of valid tags is: h1, h2, h3, h4, h5, h6, p, div.

usebutons: You can now optionally wrap each accordion item title in a <button> tag by adding usebuttons="true" to the main [accordion] shortcode. Please note that your theme may apply undesirable styles to <button> tags by default. You may need to add more custom styles to override your themes default styles. Using this setting will produce this HTML output:

<div class="accordion">
    <h3 class="accordion-title">
            Title of accordion item
    <div class="accordion-content">
        Drop-down content goes here.
    <h3 class="accordion-title">
            Second accordion item
    <div class="accordion-content">
        Drop-down content goes here.

Filtering Shortcodes

You can filter the settings and content of the shortcodes by adding some simply code to the functions.php file of your theme.

For example, you could set the openfirst option for all accordions across the entire site using:

add_filter('shortcode_atts_accordion', 'set_accordion_shortcode_defaults', 10, 3);
function set_accordion_shortcode_defaults($atts) {
    // Override the openfirst setting here
    $atts['openfirst'] = true;
    return $atts;

Compatibility Mode

If you have a theme that already includes the shortcodes [accordion] or [accordion-item] you can enable compatibility mode.

To enable compatibility mode add define('AS_COMPATIBILITY', true); to your wp-config.php file. This will add a prefix of ‘as-‘ to the two accordion shortcodes.

With compatibility mode enabled, make sure your shortcodes start with as- like this: [as-accordion]...[/as-accordion] and [as-accordion-item]...[/as-accordion-item].

Disable TinyMCE Buttons

You can optionally disable the TinyMCE extension which will remove the buttons from the editor button bar. To disable the TinyMCE extension add define('AS_TINYMCE', false); to your wp-config.php file.


For bug reports or feature requests or if you’d like to contribute to the plugin you can check everything out on Github.


  • The Accordion Group and Accordion Item shortcode buttons in the editor
  • The Accordion Group shortcode insertion dialog box
  • The Accordion Item shortcode insertion dialog box


  1. Upload the ‘accordion-shortcodes’ folder to the ‘/wp-content/plugins/’ directory.
  2. Activate the plugin through the Plugins menu in WordPress.
  3. Add the shortcodes to your content.


Why isn’t the JavaScript file loading on my site?

This is most likely caused by a poorly coded theme. This plugin makes use of the wp_footer() function to load the JavaScript file and it’s dependancy (jQuery). Check your theme to ensure that the wp_footer() function is being called right before the closing </body> tag in your theme’s footer.php file.

How can I change the look of the accordion?

No CSS is added by default to the accordion. The accordion should look fine with every theme.

That said, you can change the looking of the accordion as long as you are comfortable with editing your theme’s stylesheet. If you are familiar with that process, you can add some CSS to make the accordion look the way you want.

How can I make all accordion content disply when printing the page?

Add this CSS to your theme’s CSS stylesheet:

@media print {
    .accordion-content {
        display: block !important;
Can I use other shortcodes inside each accordion item?

Absolutely! You can use any of the WordPress format settings and headings as well.

You cannot, however nest an accordion within another accordion. This is a limitation of how WordPress processes shortcodes.

How do I accommodate fixed position headers if I’m using `scroll`?

The scroll setting accepts numeric values as well. So, instead of setting [accordion scroll="true"], you can define a pixel offset for the final scroll position like this: [accordion scroll="50"]. Set the numeric value to the pixel height of your fixed header.

Is it possible to open/close all accordions with a single button click?

Yes! Although you will need to know some simple code to get it working.

In your theme, you’ll need to have a Javascript file with the following code:

$('.js-open-everything').click(function() {
    $.each($('.accordion-title'), function(index, value) {
        if (!$(this).hasClass('open')) {

Then, you can add a button to your page:

<button class="js-open-everything">Open Everything</button>
I have a lot of extra space showing around my accordions (and other shortcodes). How can I remove it?

WordPress automatically adds paragraphs and line breaks to content formatted in the editor, so if your shortcodes aren’t formatted just right, you’ll see a lot of extra spacing. Putting this function in your theme’s functions.php file should fix it:

 * Fixes empty <p> and <br> tags showing before and after shortcodes in the
 * output content.
function pb_the_content_shortcode_fix($content) {
    $array = array(
        '<p>['    => '[',
        ']</p>'   => ']',
        ']<br />' => ']',
        ']<br>'   => ']'
    return strtr($content, $array);
add_filter('the_content', 'pb_the_content_shortcode_fix');


28 Desambra 2018
This little piece of script works, keeps on working, and hasn't failed yet, although you now do have to hand place the shortcodes since the changes started in prep for Gutenburg (the icons no longer show up on the visual editor menu). I've used it for years, all the way up to 5.0.2 .
30 Oktobra 2018
Hey mate, your plugin is so simple and so awesome that I really do hope you'll keep it around updated for us! All the best!
14 Aprily 2018
Just what I needed to make it easy to insert accordion elements anywhere in the pages, multiple times. Hope this gets an update to show as compatible with the latest version of WP (it works).
10 Martsa 2018
I needed a replacement for the [toggle] shortcode in the Canvas theme by WooThemes and this does the job perfectly. It doesn't have all the bells and whistles of [toggle], but I wasn't using those anyway. Here is the css I used, based on the example johanneseva gave in his comment (Thanks!) Mine creates a grey background for each accordion item. .accordion-title { background-image: url(./images/shortcode-toggle-open.png); background-size: 20px 20px; background-position: right center; background-repeat: no-repeat; padding-right: 26px; /* so that title does not overlap icon */ } { background-image: url(./images/shortcode-toggle-close.png); } .accordion h4.accordion-title { border-right: 5px solid #e4e8ec; /* so that icon is some distance from right border */ background-color: #e4e8ec; padding-top: 10px; padding-left: 10px; padding-bottom: 10px; cursor: pointer; } .accordion-content { border: 1px solid #ebebeb; background: #f9f9f9; padding: 10px 10px; }
Read all 69 reviews

Contributors & Developers

“Accordion Shortcodes” is open source software. The following people have contributed to this plugin.


“Accordion Shortcodes” has been translated into 1 locale. Thank you to the translators for their contributions.

Translate “Accordion Shortcodes” into your language.

Interested in development?

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



  • FIXED: Each accordion group now respects its own settings when using multiple accordions on a single page


  • FIXED: Accordions now open onkeyup instead of onkeydown to better comply with WCAG 2.1 accessibility guidelines


  • NEW: Added option to add a button tag wrapper around the accordion title
  • FIXED: better accessibility support
  • Now compatible up to WordPress 5.1


  • Now compatible up to WordPress 4.8
  • FIXED: aria-mutliselectable is now on the accordion group instead of each accordion item title


  • Now compatible up to WordPress 4.7
  • FIXED: Accordion titles now truly accessible via keyboard control


  • Now compatible up to WordPress 4.6
  • FIXED: A bug with a deprecated function in jQuery


  • NEW: Added setting to set initial state (open or closed) of individual accordion items on page load
  • NEW: Added wp-config option to disable the TinyMCE extension
  • Now compatible up to WordPress 4.5


  • FIXED: Scroll offset was ignored when an accordion was linked to from another page


  • Now compatible up to WordPress 4.4


  • Now compatible up to WordPress 4.3


FIXED: A bug where the content editor would break in custom post types


FIXED: A bug where setting both scroll and openfirst would scroll the window without user interaction


  • NEW: Accessible for users requiring tabbed keyboard navigation control (this took way too long)
  • NEW: A classname of ‘read’ is now added to accordion item titles as they are opened. This allows you to style all read accordion items
  • NEW: Compatibility mode adds a prefix to the shortcodes for themes that already include accordion shortcodes with matching names
  • FIXED: Animation queue not clearing
  • Now compatible up to WordPress 4.2


  • FIXED: An issue where openfirst would not work if title tag was set to div
  • FIXED: An issue where title tag setting was not respected when using multiple accordions on one page


  • NEW: Use multiple accordions on a single page! Each shortcode will now respect its own individual settings.
  • Now compatible up to WordPress 4.1


  • NEW: Add a custom CSS classname to your accordion item group or accordion item shortcode
  • NEW: Set an integer for scroll property to offset the scrolling by that many pixels
  • Now compatible up to WordPress 4.0


  • NEW: Buttons in the editor to easily add shortcodes with various settings
  • NEW: Support for item IDs on accordion items and direct linking to a specific item
  • NEW: Change the entire semantic structure of your accordions by using definition lists
  • ENHANCED: Class added if JavaScript is disabled (so you can style your accordions differently if necessary)
  • ENHANCED: Each accordion now has its own unique ID (accordion-1, accordion-2…) so you can target each one on a page
  • FIXED: A few incredibly small bugs/annoyances