Accordion Shortcodes

Accordion Shortcodes

Wordpress plugin

Install on Wordpress

App Details

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).

Features

  • 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]...[/accordion] 

and

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

Basic Usage Example

[accordion] [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] [/accordion] 

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. </div> <h3 class="accordion-title">Second accordion item</h3> <div class="accordion-content"> Drop-down content goes here. </div> </div> 

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;} .accordion-title.open {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] [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] [/accordion] 

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

http://yourdomain.com/your/path/#item-3 

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"> <button> Title of accordion item </button> </h3> <div class="accordion-content"> Drop-down content goes here. </div> <h3 class="accordion-title"> <button> Second accordion item </button> </h3> <div class="accordion-content"> Drop-down content goes here. </div> </div> 

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.

Issues/Suggestions

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

Pricing

Starting from $0 per month.

Check Out the Age Gate Widget

By Common Ninja

Age GateTry For Free!

App Info

Rating

Reviewers

68 reviews

Tags

Accordion
accordions
accordions plugin
Responsive accordions
shortcodes

Developed By

philbuchanan

Quick & Easy

Find the Best Wordpress plugins for you

Common Ninja has a large selection of powerful Wordpress plugins that are easy to use, fully customizable, mobile-friendly and rich with features — so be sure to check them out!

Testimonial

Testimonial plugins for Wordpress

Galleries

Galleries plugins for Wordpress

SEO

SEO plugins for Wordpress

Contact Form

Contact Form plugins for Wordpress

Forms

Forms plugins for Wordpress

Social Feeds

Social Feeds plugins for Wordpress

Social Sharing

Social Sharing plugins for Wordpress

Events Calendar

Events Calendar plugins for Wordpress

Sliders

Sliders plugins for Wordpress

Analytics

Analytics plugins for Wordpress

Reviews

Reviews plugins for Wordpress

Comments

Comments plugins for Wordpress

Portfolio

Portfolio plugins for Wordpress

Maps

Maps plugins for Wordpress

Security

Security plugins for Wordpress

Translation

Translation plugins for Wordpress

Ads

Ads plugins for Wordpress

Video Player

Video Player plugins for Wordpress

Music Player

Music Player plugins for Wordpress

Backup

Backup plugins for Wordpress

Privacy

Privacy plugins for Wordpress

Optimize

Optimize plugins for Wordpress

Chat

Chat plugins for Wordpress

Countdown

Countdown plugins for Wordpress

Email Marketing

Email Marketing plugins for Wordpress

Tabs

Tabs plugins for Wordpress

Membership

Membership plugins for Wordpress

popup

popup plugins for Wordpress

SiteMap

SiteMap plugins for Wordpress

Payment

Payment plugins for Wordpress

Coming Soon

Coming Soon plugins for Wordpress

Ecommerce

Ecommerce plugins for Wordpress

Customer Support

Customer Support plugins for Wordpress

Inventory

Inventory plugins for Wordpress

Video Player

Video Player plugins for Wordpress

Testimonials

Testimonials plugins for Wordpress

Tabs

Tabs plugins for Wordpress

Social Sharing

Social Sharing plugins for Wordpress

Social Feeds

Social Feeds plugins for Wordpress

Slider

Slider plugins for Wordpress

Reviews

Reviews plugins for Wordpress

Portfolio

Portfolio plugins for Wordpress

Membership

Membership plugins for Wordpress

Forms

Forms plugins for Wordpress

Events Calendar

Events Calendar plugins for Wordpress

Contact

Contact plugins for Wordpress

Comments

Comments plugins for Wordpress

Analytics

Analytics plugins for Wordpress

Common Ninja Apps

Some of the best Common Ninja plugins for Wordpress

Browse our extensive collection of compatible plugins, and easily embed them on any website, blog, online store, e-commerce platform, or site builder.

Age Gate for Wordpress logo

Age Gate

Use an age verification popup to validate visitor age, meet regulatory requirements, and ensure only eligible users access restricted content.

Events Calendar for Wordpress logo

Events Calendar

Add an events calendar to your site so visitors can view upcoming activities, improving engagement and event visibility.

Device Mockup for Wordpress logo

Device Mockup

Show products, apps, or designs inside a clean device mockup that improves visualization, builds credibility, and helps visitors make confident decisions.

Consent Form for Wordpress logo

Consent Form

Create consent forms that collect signatures, save submissions, send notifications, and help you manage approvals efficiently.

Logo Slider for Wordpress logo

Logo Slider

Add a logo slider to your site to showcase clients and partners, strengthen brand credibility, and build trust with new visitors.

Reviews Trust Box for Wordpress logo

Reviews Trust Box

Display ratings from multiple platforms in a reviews trust box that builds credibility, social proof, and boosts conversions.

YouTube Carousel for Wordpress logo

YouTube Carousel

Show YouTube videos with a YouTube carousel that displays clips in a smooth, customizable layout to boost visibility and keep visitors engaged.

Email Subscription Form for Wordpress logo

Email Subscription Form

Capture email leads with an email subscription form that collects addresses, saves entries, sends notifications, and helps grow your audience.

Company Branch Flip Cards for Wordpress logo

Company Branch Flip Cards

Display locations with company branch flip cards that help customers find nearby offices, understand key details, and enjoy a smoother overall experience.

All in One Reviews for Wordpress logo

All in One Reviews

Display and manage customer reviews from multiple platforms in one place to build trust and highlight brand credibility.

Catalog for Wordpress logo

Catalog

Create and customize product catalogs with a catalog widget that organizes items clearly, improves browsing, and helps visitors explore your offerings easily.

RSS Feed Carousel for Wordpress logo

RSS Feed Carousel

Show RSS content with an RSS feed carousel that updates automatically, displays posts in a smooth scrolling layout, and keeps visitors engaged.

Discover Apps By Platform

Discover the best apps for your website

WordPress
Wix
Shopify
Weebly
Webflow
Joomla
PrestaShop
Shift4Shop
WebsiteX5
MODX
Opencart
NopCommerce

Common Ninja Search Engine

The Common Ninja Search Engine platform helps website builders find the best site widgets, apps, plugins, tools, add-ons, and extensions! Compatible with all major website building platforms - big or small - and updated regularly, our Search Engine tool provides you with the business tools your site needs!

Multiple platforms