0

I'm creating some shortcodes that will build an accordion. I need the following:

[accordion]

    [accordion-item title="Trigger Text"]Panel Content[/accordion-item]

[/accordion]

I want to create a button in TinyMCE to make it easier for the client to build the accordion as the shortcode syntax will be too confusing for them. From what I can tell, there is no way to create a pop-up that will allow for repeatable items (each accordion will have varying numbers of items) within the TinyMCE pop-up, so I was then thinking of just having a button that will allow them to do an accordion item. This means I need someone of prepending and appending the [accordion] wrapper around it.

Is there a way I can find the first instance of a shortcode and put the necessary HTML code before it and likewise, after the last instance but the closing tag after the last time the [accordion-item] shortcode is used?

My only other idea was having the client indicate if the panel they are adding is the first or last within the accordion group. This is fine, to begin with, but could confuse them if they return and add more items at a later date.

I'd prefer to do this accordion as custom - I do not want to use an already existing plugin as I don't want to have to rely on updates etc. from plugin developers.

Of course, I am open to any other suggestion in being able to make this process easy for my client while still allowing the use of my accordion markup/script.

Any advice would be greatly appreciated.

Thanks, Jess

0

Basically, nested shortcodes should not be used. As you say it ends as being too complex for an author to write one and therefor it will be too complex to understand and modify.

A better approach to such things is either insert a menu with a shortcode, or generate the accordion dynamically based on a specific HTML element (h2 for example)

  • When you say 'generate the accordion dynamically' are you talking about using javascript/jquery, or using php somehow? – jesspritchard Jul 6 '17 at 23:25
  • either, probably JS should be easier to do, but it should be possible to do in php as well – Mark Kaplun Jul 7 '17 at 4:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.